最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

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

Webpack crifan 550浏览 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
> react-hot-boilerplate@1.0.0 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! react-hot-boilerplate@1.0.0 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 react-hot-boilerplate@1.0.0 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
67 queries in 0.124 seconds, using 18.93MB memory