参考来源:https://stackoverflow.com/que…webpack配置,将index.js变为index.ejs模板const HtmlWebpackPlugin = require(‘html-webpack-plugin’)module.exports = { entry: ‘index.js’, output: { path: __dirname + ‘/dist’, filename: ‘index_bundle.js’ }, plugins: [ new HtmlWebpackPlugin({ filename: dirname + ‘/dist/index.ejs’, }) ]}webpack的入口文件(index.js)添加__webpack_nonce = ‘<%=nonce%>’;服务端程序,遇到index.js的请求,就替换掉<%=nonce%>