使用html-webpack-plugin插件,可以在打包后自動生成一個index.html文件,這個index.html文件里會把打包后的靜態資源引入。
相關配置如下面所受
const path = require('path') const htmlWebpackPlugin = require('html-webpack-plugin') module.exports = { entry: "./src/main.js", output:{ filename: 'index.js', path:path.resolve(__dirname, 'build') }, module:{ }, plugins:[ new htmlWebpackPlugin({ template:"./src/index.html" }) ], mode:'development' }
其中template為指定打包的html使用的模板。