最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】webpack-dev-server出错:Deprecation notice: CommonsChunkPlugin now only takes a single argument. Either an options

Webpack crifan 1905浏览 0评论

折腾:

【已解决】把react-hot-boilerplate改为用最新webpack-dev-server去调试代码

期间,

webpack.config.js

  plugins: [
    // new webpack.ProvidePlugin({
    //   $: ‘jquery’,
    //   ‘window.jQuery’: ‘jquery’,
    //   jQuery: ‘jquery’,
    //   ‘window.$’: ‘jquery’,
    // }),
    new webpack.optimize.CommonsChunkPlugin(‘vendor’, ‘vendor.bundle.js’),
    new webpack.HotModuleReplacementPlugin()
    // new webpack.optimize.UglifyJsPlugin({
    //   minimize: true
    // })
  ],

出错:

➜  react-hot-boilerplate git:(master) ✗ npm run dev
> [email protected] dev /Users/crifan/dev/dev_root/daryun/Projects/xxx/sourcecode/web/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate
> cross-env NODE_ENV=development webpack-dev-server –progress –colors –inline –hot –open
process.env.NODE_ENV=development, isProd=false
/Users/crifan/dev/dev_root/daryun/Projects/xxxsourcecode/web/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js:10
            throw new Error(`Deprecation notice: CommonsChunkPlugin now only takes a single argument. Either an options
            ^
Error: Deprecation notice: CommonsChunkPlugin now only takes a single argument. Either an options
object *or* the name of the chunk.
Example: if your old code looked like this:
    new webpack.optimize.CommonsChunkPlugin(‘vendor’, ‘vendor.bundle.js’)
You would change it to:
    new webpack.optimize.CommonsChunkPlugin({ name: ‘vendor’, filename: ‘vendor.bundle.js’ })
The available options are:
    name: string
    names: string[]
    filename: string
    minChunks: number
    chunks: string[]
    children: boolean
    async: boolean
    minSize: number
    at new CommonsChunkPlugin (/Users/crifan/dev/dev_root/daryun/Projects/xxxx/sourcecode/web/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/node_modules/webpack/lib/optimize/CommonsChunkPlugin.js:10:10)
    at Object.<anonymous> (/Users/crifan/dev/dev_root/daryun/Projects/xxxx/sourcecode/web/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/webpack.config.js:40:5)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at requireConfig (/Users/crifan/dev/dev_root/daryun/Projects/xxxx/sourcecode/web/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/node_modules/webpack/bin/convert-argv.js:97:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `cross-env NODE_ENV=development webpack-dev-server –progress –colors –inline –hot –open`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/crifan/.npm/_logs/2017-08-14T06_13_20_449Z-debug.log

通过Deprecation notice感觉是:

Webpack 3,写法不同了

Deprecation notice: CommonsChunkPlugin now only takes a single argument. Either an options

Deprecation notice: CommonsChunkPlugin now only takes a single argument. Either an options · Issue #256 · ant-tool/atool-build

javascript – “CommonsChunkPlugin now only takes a single argument.。。。。 – SegmentFault

【总结】

原来是:

此处之前用的webpack 1.x的配置,

现在升级到3.x的话,之前配置出错,从:

    new webpack.optimize.CommonsChunkPlugin(‘vendor’, ‘vendor.bundle.js’),

改为:

    new webpack.optimize.CommonsChunkPlugin({
      name: ‘vendor’,
      filename: ‘vendor.bundle.js’
    }),

即可。

转载请注明:在路上 » 【已解决】webpack-dev-server出错:Deprecation notice: CommonsChunkPlugin now only takes a single argument. Either an options

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.187 seconds, using 22.13MB memory