0

the construct of the object

I want to extract 'vue' to a chunk, 'jquery' to a chunk and something relating with 'vue',like 'vuex', 'vue-router' to another chunk. and what should do with CommonChunkPlugin?

These codes were my config, It conbine the vue and the jquery with others

new webpack.optimize.CommonsChunkPlugin(
  name: 'vendor',
  minChunks: function(module, count) {
    return (
      module.resource &&
      /\.js$/.test(module.resource) && 
      module.resource.indexOf( path.join(__dirname, '../node_modules') ) === 0
    )
  }
}),
new webpack.optimize.CommonsChunkPlugin({
  name: 'manifest',
  chunks: ['vendor']
})

entry: {
  collegedaily: '.src/collegedaily/collegedaily.js',
  editor: './src/editor/editor.js',
  sharepage: './src/share/blog.js',
  agreement: './src/agreement/agreement.js',
  invitationCode: './src/invitationCode/invitationCode.js'
}

thank you very much!

oklas
  • 7,935
  • 2
  • 26
  • 42
Tony_zha
  • 97
  • 6
  • What you have try to done? Do you have you problems or errors? – oklas May 26 '17 at 09:15
  • ` new webpack.optimize.CommonsChunkPlugin( name: 'vendor', minChunks: function(module, count) { return ( module.resource && /\.js$/.test(module.resource) && module.resource.indexOf( path.join(__dirname, '../node_modules') ) === 0 ) } }), new webpack.optimize.CommonsChunkPlugin({ name: 'manifest', chunks: ['vendor'] })` These codes were my config, It conbine the vue and the jquery with others,but what I what is that vue and jquery can be separated chunk – Tony_zha May 26 '17 at 09:30

1 Answers1

0

You can create two new instances of CommonsChunkPlugin and make them like this

new webpack.optimize.CommonsChunkPlugin({
   name: 'vue',
   minChunks: function(module, count) {
     return  module.resource && (/vue/).test(module.resource)    
   }
}),
new webpack.optimize.CommonsChunkPlugin({
   name: 'jquery',
   minChunks: function(module, count) {
     return  module.resource && (/jquery/).test(module.resource)    
   }
}),
Ematipico
  • 1,181
  • 1
  • 9
  • 14
  • I make my config like what you support.It do extract vue and vue-related to a chunk, but jquery was still in the vendor chunk.And the new jquery chunk was filled with webpack bootstrap logic which is very similar with manifest chunk. – Tony_zha May 26 '17 at 12:33