webpack配置错误

时间:2018-04-09 13:28:46

标签: reactjs webpack jsx

我尝试配置web pack以响应Web应用程序,它一直告诉我使用 npm install -D webpack-cli

The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
module.js:557
    throw err;
    ^

当我做了它问我的时候它给了我这个错误:

 C:\Users\Desktop\lazabre1>webpack-dev-server
C:\Users\Desktop\lazabre1\webpack.config.js:59
        new webpack.NoErrorsPlugin()
        ^

这是我的webpack.config.js文件:

var webpack = require('webpack');
var path = require('path');

module.exports = {
    devtool: 'inline-source-map',
    entry: [
        'webpack-dev-server/client?http://127.0.0.1:8080/',
        'webpack/hot/only-dev-server',
        './src'

    ],

    output: {

        path: path.join(__dirname, 'public'),

        filename: 'bundle.js'

    },

    resolve: {
        modulesDirectories: ['node_modules', 'src'],
        extensions: ['', '.js']
    },
    module: {
        loaders: [
        {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loaders: ['react-hot', 'babel?presets[]=react,presets[]=es2015']
        }
        ]
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin()
    ]

};

我有两个问题:第一 - 如何解决这个问题//
                     第二 - npm install webpacknpm install webpack-cli之间有什么区别。

1 个答案:

答案 0 :(得分:1)

您正在使用为Webpack 1编写的配置文件(我想,通过使用module.loader密钥和NoErrorsPlugin)并使用Webpack 4(如果您没有另外指定,则通过请求使用默认情况下不包含的CLI。)

按照documentation升级您的配置,然后更新NoErrorsPlugin

webpack-cli是一个从命令行工具中使用webpack的包(你想要做的)。