inline your script when using webpack requiring html-webpack-plugin
- node >= 6.0 with npm
- html-webpack-plugin
npm install inline-script-webpack-plugin --save-dev
#or
npm i inline-script-webpack-plugin -D
for webpack.config.js:
//single scriptmodule.exports={entry: {//...inline: []},//...plugins: [//...newHtmlWebpackPlugin(),newInlineScriptWebpackPlugin(),//default chunk name will be `inline` if no name option is given//...]}//multi scripts and custom entrymodule.exports={entry: {//...foo: [],bar: []},//...plugins: [//...newHtmlWebpackPlugin(),newInlineScriptWebpackPlugin({names:['foo','bar']}),//multi scripts require names options//...]}for index.html or template:
<!doctype html><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><metahttp-equiv="X-UA-Compatible" content="ie=edge"><title>Template</title><!--multi and ordered--><%=htmlWebpackPlugin.files.foo%><%=htmlWebpackPlugin.files.bar%></head><body><!--single--><%=htmlWebpackPlugin.files.inline%></body></html>