2

我试图从我的css提取常见块根据wiki section。我知道这个文档是用于webpack 1,但是用于webpack 2seems like there is no corresponding example yet。我用下面的WebPack配置:ExtractTextPlugin和CommonsChunkPlugin提取常见样式

module.exports = { 
    context: srcPath, 
    entry: { 
     foo: './css/pages/foo.css', 
     bar: './css/pages/bar.css' 
    }, 
    output: { 
     path: distPath, 
     publicPath: '/assets/', 
     filename: '[name].js' 
    }, 
    module: { 
     rules: [{ 
      test: /\.css$/, 
      use: ExtractTextPlugin.extract([ 
       'css-loader' 
      ]) 
     }] 
    }, 
    plugins: [ 
     new webpack.optimize.CommonsChunkPlugin({ 
      name: 'common', 
      minChunks: 2 
     }), 
     new ExtractTextPlugin({ 
      filename: 'css/[name].[contenthash:base64:5].css', 
      allChunks: true 
     }) 
    ] 
}; 

我不知道为什么common.css不是建设后出现。只需common.js,foo.js,bar.js,foo.cssbar.css。我错过了什么吗?我是webpack新手。

谢谢。

+0

对我来说似乎很奇怪 - 入口点是css文件?为了我的帮助,我需要澄清一下 –

+0

@VISHALDAGA其实我也有js文件作为条目,我只是简单的例子。 – user1636505

回答