首页 > 代码库 > Webpack 学习记录-02
Webpack 学习记录-02
想在HTMl页面中生成内联的JS代码:
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title><%= htmlWebpackPlugin.options.title %></title> <script type="text/javascript"> <%= compilation.assets[htmlWebpackPlugin.files.chunks.main.entry.substr(htmlWebpackPlugin.files.publicPath.length)].source() %> </script> </head> <body> <% for (var chk in htmlWebpackPlugin.files.chunks) {%> <% if(chk!=="main") {%> <script type="text/javascript" src="http://www.mamicode.com/"></script> <% } %> <% } %> </body> </html>
webpack.config.js
var htmlWebpackPlugin=require("html-webpack-plugin"); module.exports={ entry:{ main:‘./src/script/main.js‘, a:‘./src/script/a.js‘, b:"./src/script/b.js", c:"./src/script/c.js" }, output:{ path:__dirname+"/dist", filename:"js/[name].js" }, plugins:[ new htmlWebpackPlugin({ template:‘index.html‘, inject:‘body‘, filename:"a.html", title:"this is a.html", chunks:[‘main‘,‘a‘] }), new htmlWebpackPlugin({ template:"index.html", inject:‘body‘, filename:"b.html", title:"this is b.html", chunks:[‘main‘,‘a‘] }), new htmlWebpackPlugin({ template:"index.html", inject:‘body‘, filename:"c.html", title:"this is c.html", chunks:[‘main‘,‘c‘] }) ] }
开始拼写错了<%= compilation.assets[htmlWebpackPlugin.files.chunks.main.entry.substr(htmlWebpackPlugin.files.publicPath.length)].source() %>
</script> 写错为:<%= compilation.asserts[htmlWebpackPlugin.files.chunks.main.entry.substr(htmlWebpackPlugin.files.publicPath.length)].source() %>
</script>
一直报错:
Webpack 学习记录-02
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。