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.aoyou183.cn/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. docker不顯示端口映射呢?2. angular.js - 關于$apply()3. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””4. macos - mac下docker如何設置代理5. MySQL數據庫中文亂碼的原因6. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?7. docker gitlab 如何git clone?8. mysql - 新浪微博中的關注功能是如何設計表結構的?9. css - C#與java開發Windows程序哪個好?10. docker-compose 為何找不到配置文件?
