javascript - webpack dllPlugin如何打包vendor到html里面?
問題描述
使用html-webpack-plugin只能將應用的bundle.js寫到html,不能將dll生成的vendor寫入,有沒有什么辦法?
問題解答
回答1:可以使用 add-asset-html-webpack-plugin,將打包后的文件,加入html中。通過以下方式引用,或者參考下我的vue-2.0template
喜歡的話可以給個star
new HtmlWebpackPlugin({ filename: itemPath, template: template, inject: true, title: item.title || ’Document’, chunks: chunks, chunksSortMode: ’dependency’,}),new AddAssetHtmlPlugin([{ filepath: path.resolve(__dirname, config.build.dll.basePath, config.build.dll.fileName), outputPath: utils.assetsPath(’common/js/’), publicPath: path.join(config.build.publicPath, ’common/js’), includeSourcemap: true}])回答2:
自問自答:1、 將vendor.js生成到/dll/,2、 template.html使用html-webpack-plugin的模板語法
<body><script src='http://www.intensediesel.com/wenda/<%= htmlWebpackPlugin.optiions.vendor %>'></script></body>
3、 設置webpack.dev.config.js
//...plugins:[ new HTMLPlugin({template: ’./src/template.html’,filename: ’index.html’vendor: ’/dll/’ + manifest.name + ’.js/’ //manifest就是dll生成的json })]
僅僅用于開發環境
相關文章:
1. html - vue項目中用到了elementUI問題2. java - 如何寫一個intellij-idea插件,實現編譯時修改源代碼的目的3. javascript - 有什么比較好的網頁版shell前端組件?4. javascript - 如何將一個div始終固定在某個位置;無論屏幕和分辨率怎么變化;div位置始終不變5. javascript - 求解答:實例對象調用constructor,此時constructor內的this的指向?6. javascript - vscode alt+shift+f 格式化js代碼,通不過eslint的代碼風格檢查怎么辦。。。7. html5 - 有可以一次性把所有 css外部樣式轉為html標簽內style=" "的方法嗎?8. javascript - [js]為什么畫布里不出現圖片呢?在線等9. java 中Long 類型如何轉換成Double?10. javascript - 原生canvas中如何獲取到觸摸事件的canvas內坐標?
