如何使用webpack捆绑Create React App?

时间:2017-12-26 23:33:21

标签: reactjs webpack

我将react应用程序捆绑到一个文件中,以便从Scala Play后端提供服务更简单。

我的webpack.config.js看起来像这样

    const webpack = require("webpack")
    const path = require("path")

    module.exports = {
        entry: {
            frontApp: "./src/index.js"
        },
        output: {
            path: path.join(__dirname, "./node/target/"),
            filename: "app.bundle.js"
        },
        module: {
            rules: [
                {
                    test: /\.js?/,
                    exclude: /node_modules/,
                    use: {
                        loader: "babel-loader"
                    }
                }
            ]
        }
    }

错误

ERROR in ./src/index.js
Module build failed: SyntaxError: Unexpected token (7:16)

  5 | import registerServiceWorker from './registerServiceWorker';
  6 | 
> 7 | ReactDOM.render(<JapaneseApp />, document.getElementById('root'));
    |                 ^
  8 | registerServiceWorker();
  9 | 

和package.json

  {
    "name": "translation-app-react",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "es6-promise": "^4.1.1",
        "isomorphic-fetch": "^2.2.1",
        "react": "^15.6.1",
        "react-dom": "^15.6.1",
        "react-scripts": "1.0.10",
        "wanakana": "^2.2.4"
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "webpack",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
    }
  }

我是否缺少webpack读取React语法的依赖项?

0 个答案:

没有答案