Node v9 + Webpack v4 + extract-text-webpack-plugin =编译错误

phi*_*ipp 17 webpack

//webpack.config.js -- shortened for convenience

const 
  ExtractTextPlugin = require("extract-text-webpack-plugin"),

  extractSass = new ExtractTextPlugin({
    filename: "Css/[name].css",
    allChunks: true
  }),

  //…
  config: {
    module: {
      rules: [
        //…
        {
          test: /\.scss$/,
          use: extractSass.extract([ 'css-loader', 'sass-loader' ])
        }
        //…
      ]

    },

    plugins: [
      extractSass
    ]
  }

  module.exports = config;
Run Code Online (Sandbox Code Playgroud)

使用时:

         0% compiling(node:333) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
(node:333) DeprecationWarning: Tapable.apply is deprecated. Call apply on the plugin directly instead                                                                                                                                                   
        77% module and chunk tree optimization unnamed compat plugin/xxx/node_modules/webpack/lib/Chunk.js:460
                throw new Error(
                ^

 Error: Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead
    at Chunk.get (/xxx/node_modules/webpack/lib/Chunk.js:460:9)
    at /xxx/node_modules/extract-text-webpack-plugin/dist/index.js:176:48
    at Array.forEach (<anonymous>)
    at /xxx/node_modules/extract-text-webpack-plugin/dist/index.js:171:18
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/xxx/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:12:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (/xxx/node_modules/tapable/lib/Hook.js:35:21)
    at Compilation.seal (/xxx/node_modules/webpack/lib/Compilation.js:881:27)
    at hooks.make.callAsync.err (/xxx/node_modules/webpack/lib/Compiler.js:464:17)
    at _err0 (eval at create (/xxx/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:11:1)
    at _addModuleChain (/xxx/node_modules/webpack/lib/Compilation.js:749:12)
    at processModuleDependencies.err (/xxx/node_modules/webpack/lib/Compilation.js:688:9)
    at process._tickCallback (internal/process/next_tick.js:150:11)
Run Code Online (Sandbox Code Playgroud)

该设置一直有效,直到webpack v4.禁用插件会使错误消失.我发现webpacks插件系统已经改变,但我无法弄清楚如何修复该错误.

phi*_*ipp 41

如上所述这里的问题是,extract-text-webpack-plugin 需要为了一起工作进行升级webpack v4.所以:

npm install extract-text-webpack-plugin@next
Run Code Online (Sandbox Code Playgroud)

肯定会解决问题.


小智 7

对于Webpack v4,似乎不推荐使用extract-text-webpack-plugin.请参阅自述文件,其中说:

⚠️从webpack v4开始,extract-text-webpack-plugin不应该用于css.请改用mini-css-extract-plugin.

本期"插件的未来与迷你CSS提取插件"提供了有关弃用的更多信息.