使用html-webpack-plugin
只能将应用的bundle.js
写到html,不能将dll生成的vendor写入,有没有什么办法?
使用html-webpack-plugin
只能将应用的bundle.js
写到html,不能将dll生成的vendor写入,有没有什么办法?
自问自答:
1、 将vendor.js
生成到/dll/
,
2、 template.html使用html-webpack-plugin的模板语法
<body>
<% if(htmlWebpackPlugin.options.isDev) {%>
<script src="<%= htmlWebpackPlugin.options.vendor %>"></script>
<% } %>
</body>
3、 设置webpack.dev.config.js
const manifest = require('dist/dll/manifest.json')
//...
plugins:[
new HTMLPlugin({
template: './src/template.html',
filename: 'index.html'
vendor: '/dll/' + manifest.name + '.js' //manifest就是dll生成的json
})
]
仅仅用于开发环境
10 回答11.2k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
可以使用 add-asset-html-webpack-plugin,将打包后的文件,加入html中。
通过以下方式引用,或者参考下我的vue-2.0template
喜欢的话可以给个star