react.js和webpack 2,需要一个解决方案

时间:2017-02-12 06:24:34

标签: javascript node.js reactjs webpack-2

我正在使用create-react-app和webpack 2进行示例教程,但我收到此错误:

enter image description here

这是我的package.json:

'02-02-2017' : '<span>Some txt from database</span><span>Some txt from database</span>', '02-08-2017' : '<span>Some txt from database</span><span>Some txt from database</span>'

我的webpack.config.js:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "babel-core": "^6.22.1",
    "babel-loader": "^6.2.10",
    "babel-preset-latest-minimal": "^1.1.2",
    "babel-preset-react": "^6.22.0",
    "css-loader": "^0.26.1",
    "html-loader": "^0.4.4",
    "json-loader": "^0.5.4",
    "node-sass": "^4.5.0",
    "raw-loader": "^0.5.1",
    "react-scripts": "0.8.5",
    "sass-loader": "^5.0.1",
    "style-loader": "^0.13.1",
    "svgo-loader": "^1.1.2",
    "webpack": "^2.2.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "dependencies": {
    "file-loader": "^0.10.0",
    "react": "^15.4.2",
    "react-dom": "^15.4.2",
    "react-router": "^3.0.2"
  }
}

我的index.jsx:

module.exports = {
  context: __dirname,
  entry: {
    app: '../src/index.jsx', 

  },
  output: {
    path: './build',
    filename: 'app.js',
  },
  module: {
    loaders: [{
    test: /\.html$/,
    loader: 'html-loader',
    query: {
      minimize: true
    }
  },{
      test: /(\.jsx?)$/,
      loader: 'babel-loader',
      exclude: /(node_modules)/,
      query: {
        presets: ['latest-minimal', 'react'],
      }
    }, {
      test: /\.css$/,
      exclude: /(node_modules)/,
      use: ['style-loader', 'css-loader']
    },{
      test: /\.svg$/,
      use: [{
        loader: 'file-loader'
      }, {
        loader: 'svgo-loader',
        options: {
          plugins: [{
            removeTitle: true
          }, {
            convertColors: {
              shorthex: false
            }
          }, {
            convertPathData: false
          }]
        }
      }]
    }]
  }
}

3 个答案:

答案 0 :(得分:1)

create-react-app是为webpack 1编写的。你已经更新到webpack 2,它只在一个月前发布。有一些语法更改会破坏版本1 webpack.config.js文件。以下是迁移指南:

https://webpack.js.org/guides/migrating/

答案 1 :(得分:0)

我创建了一个使用create-react-app并使用webpack 2的bolierplate 你可以从那里进行配置。

https://github.com/sagarrabadiya/react-boilerplate

答案 2 :(得分:0)

如果你还没找到,我认为this非常好