关于webpack4配置react报错的问题

来源:5-3 webpack热加载配置(中)

Jokky

2018-08-08

http://img.mukewang.com/szimg/5b6ae1ed0001675911400732.jpg

http://img.mukewang.com/szimg/5b6ae1ed000174ec32881890.jpg

webpack.config.js

var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');
module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-react']
                    }
                }
            },
            {
                test: /\.(png|jpg|gif)$/,
                use: [
                    {
                        loader: "file-loader",
                        options: {}
                    }
                ]
            }
            ,
            {
                test: /\.css$/,
                use: [
                    { loader: 'style-loader' },
                    { loader: 'css-loader?modules' },
                ]
            },
        ]
    }

package.json

{
  "name": "myreact",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.0.0-beta.56",
    "@babel/preset-react": "^7.0.0-beta.56",
    "babel-loader": "^8.0.0-beta.4",
    "webpack": "^4.16.5",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^3.1.5"
  }
}


写回答

2回答

Jokky

提问者

2018-08-09

关于warnning,已经找到原因,因为冲突,执行命令时改成webpack --mode=production即可

webpack.config.js

var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');
module.exports = {
  context: path.join(__dirname),
  devtool: debug ? "inline-sourcemap" : null,
  entry: "./src/js/index.js",
  module: {
    loaders: [
      {
        test: /\.js?$/,
        exclude: /(node_modules)/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015']
        }
      }
    ]
  },
  output: {
    path: __dirname,
    filename: "./src/bundle.js"
  },
  resolve: {
  extensions: ['', '.js', '.jsx']
},
  plugins: debug ? [] : [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
  ],
};

https://github.com/babel/babel-loader/issues/173

这边有解决方案,不过就是有点没看懂他们说的什么意思,可以解释下吗?

0
0

Jokky

提问者

2018-08-08

主要是想知道这个警告是什么问题,怎么到webpack4里面会出现这种问题

0
0

结合基础与实战学习React.js 独立开发新闻头条平台

轻松入门 React 开发,React Router 4 与 Webpack 2 完美升级项目

2768 学习 · 2126 问题

查看课程