webpack4中在html页面的<script>标签里写<%= %>会报下面的错误,大家有遇到吗
The script element allows authors to include dynamic script and data blocks in their documents. The element does not represent content for the user.
The script element allows authors to include dynamic script and data blocks in their documents. The element does not represent content for the user.
2019-01-25
webpack4 确实会报错。
要把js弄成inline的话,有另一个方法,需要一个插件 叫:html-webpack-inline-source-plugin,用来将静态资源inline注入。
安装:
npm install html-webpack-inline-source-plugin --save-dev
在webpack.config.js头部写上:
var htmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin')
在需要inline的地方加上:
new htmlWebpackPlugin({ //... 之前的代码 inlineSource: '.(js|css)$', // 正则表达式, 匹配js文件和css文件,你可以修改匹配特定的文件 }),
在plugins的最后加上:
plugins:[ //... 之前的代码 new htmlWebpackInlineSourcePlugin() ]
之后,npm run webpack 打包一下就可以了。
举报