2017-05-26 119 views
0

the construct of the object如何配置我的webpack.config.js提取這些dependances?

我想提取「VUE」來一大塊,「jQuery的」來一大塊,並與「VUE」有關的東西,像「vuex」,「VUE路由器」到另一塊。又該用CommonChunkPlugin呢?

這些代碼是我的配置,它conbine的VUE和與他人

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' 
} 

非常感謝你了jQuery!

+0

什麼你已經嘗試做了什麼?你有沒有問題或錯誤? – oklas

+0

'新webpack.optimize.CommonsChunkPlugin(名稱: '供應商', minChunks:功能(模塊,計數){ 回報( module.resource && /\.js$/.test(module.resource)&& 模塊.resource.indexOf( path.join(__目錄名稱,」 ../node_modules') )=== 0 ) } }), 新webpack.optimize.CommonsChunkPlugin({ 名: '清單', 大塊:[「供應商」] })'這些代碼是我的配置,它conbine的VUE並與他人jQuery的,但我那是什麼VUE和jQuery可以分開塊 –

回答

0

您可以創建CommonsChunkPlugin的兩個新實例,讓他們像這樣

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)  
    } 
}), 
+0

使我的像你support.It做什麼提取物VUE和VUE相關的塊,但jQuery的配置仍然在供應商chunk.And新的jQuery塊中瀰漫着的WebPack引導邏輯是有明顯的大塊非常相似。 –

相關問題