javascript - webpack dllPlugin如何打包vendor到html里面?
問題描述
使用html-webpack-plugin只能將應(yīng)用的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.4tl426be.cn/wenda/<%= htmlWebpackPlugin.optiions.vendor %>'></script></body>
3、 設(shè)置webpack.dev.config.js
//...plugins:[ new HTMLPlugin({template: ’./src/template.html’,filename: ’index.html’vendor: ’/dll/’ + manifest.name + ’.js/’ //manifest就是dll生成的json })]
僅僅用于開發(fā)環(huán)境
相關(guān)文章:
1. bootstrp是col-md-12列的,只有col-md-10有內(nèi)容,可以讓沒有內(nèi)容的不占據(jù)位置嗎;2. java - 如何用圖畫的方式有效地表示多線程?3. thinkPHP5中獲取數(shù)據(jù)庫數(shù)據(jù)后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙4. python - Fiddler+Android模擬器抓取app,json數(shù)據(jù)被加密了,如何解析?5. 在windows下安裝docker Toolbox 啟動Docker Quickstart Terminal 失敗!6. python 3.4 error: Microsoft Visual C++ 10.0 is required7. html5 - 剛接觸H5,為什么我覺得很多標簽都沒什么用呢?8. 我的怎么不顯示啊,話說有沒有QQ群什么的9. android - 請問一下 類似QQ音樂底部播放 在每個頁面都顯示 是怎么做的?10. html5 - 現(xiàn)在前端設(shè)備和網(wǎng)速都提高了,為什么要用服務(wù)器端渲染?
