課程
/前端開發
/前端工具
/webpack深入與實戰
為何我script標簽里寫<%=>會報錯,你們有遇到么?我運行也能出結果
2017-03-13
源自:webpack深入與實戰 3-3
正在回答
可以用
來生成inline script
首先先用npm 安裝,然后再到webpack.config.js當中引用
再在plugins當中設置需要用內斂方法嵌入的文件,然后新建source-plugin對象即可
const?htmlWebpackPlugin?=?require('html-webpack-plugin') const?HtmlWebpackInlineSourcePlugin?=?require('html-webpack-inline-source-plugin') ?plugins:?[ ????new?htmlWebpackPlugin({ ?????????filename:?'index.html',????? ?????????template:?'index.html',????? ?????????inject:?'head',???? ??????????inlineSource:?'.(main.js)$' ????}),??? ????????new?HtmlWebpackInlineSourcePlugin()? ?]
<script?type="text/html"> <%=compilation.assets[htmlWebpackPlugin.files.chunks.main.entry.substr(htmlWebpackPlugin.files.publicPath.length)].source()%> </script>
內心爆炸,不管了...
這個問題知道是為嘛了沒?
b.html的配置中: excludeChunks:['a','c','main']改為excludeChunks:['a','c'], 也就是說接口里用main.entry寫的方法(就是這段 <%=?compilation.assets[htmlWebpackPlugin.files.chunks.main.entry.substr(htmlWebpackPlugin.files.publicPath.length)].source()?%>),那么在webpack.config文件中的excludeChunks里就不能把‘main’排除掉
求同,速度來人回答 ?!?。。。。。。。?/p>
你試試把有帶hash的去掉,估計就可以
<script type="text/javascript">?<%=compilation.assets[htmlWebpackPlugin.files.chunks.main.entry.substr(htmlWebpackPlugin.files.publicPath.length)].source() %></script>
這句有報錯,很郁悶
木主0703
<%= %>少寫了個%號
舒戈丶2m
木主0703 回復 舒戈丶2m
舉報
webpack實戰教程,用真實項目帶你探索 webpack 強大的功能
2 回答webpack4中在html頁面的<script>標簽里寫<%= %>會報下面的錯誤,大家有遇到嗎
3 回答script標簽里的<%= %>報錯問題怎么解決?
2 回答script標簽插入<%=%>報錯 怎么解決
7 回答webpack中 <script>標簽中<%%>報錯
2 回答運行npm run webpack 報錯,直接運行webpack不會報錯
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2019-03-13
可以用
html-webpack-inline-source-plugin
來生成inline script
首先先用npm 安裝,然后再到webpack.config.js當中引用
再在plugins當中設置需要用內斂方法嵌入的文件,然后新建source-plugin對象即可
2018-10-22
2018-10-12
內心爆炸,不管了...
2018-03-20
這個問題知道是為嘛了沒?
2017-07-01
2017-05-06
求同,速度來人回答 ?!?。。。。。。。?/p>
2017-03-30
你試試把有帶hash的去掉,估計就可以
2017-03-14
<script type="text/javascript">
?<%=compilation.assets[htmlWebpackPlugin.files.chunks.main.entry.substr(htmlWebpackPlugin.files.publicPath.length)].source() %>
</script>
這句有報錯,很郁悶
2017-03-13
<%= %>少寫了個%號