webpack.config.js
onst webpack = require('webpack')module.exports = {...plugins: [new webpack.BannerPlugin('最终版权归AAA所有')]
}
真实发布项目时,发布的是dist文件夹中的内容,但是dist文件夹中如果没有index.html文件,name打包的js等文件就没有意义了。
所以,我们需要将index.html文件导包放到dist文件夹中,这个时候就可以使用HtmlWebpackPlugin插件。
自动生成一个index.html文件(可以指定模板来生成)
将打包的js文件,自动通过script标签插入到body中。
npm install html-webpack-plugin@3.2.0 --save-dev
4.使用插件,修改webpack.config.js文件中的plugins部分的内容如下
这里的template表示根据什么模板来生成index.html
另外,我们需要删除之前在output中添加的publicPath属性
否则插入的script标签中的src可能会有问题
plugins: [new webpack.BannerPlugin('最终版权归AAA所有')// new HtmlWebpackPlugin()new HtmlWebpackPlugin({template: 'index.html'})
]
npm install uglifyjs-webpack-plugin --save-dev
const uglifuJsPlugin = require('uglifujs-webpack-plugin')plugins: [new uglifyJsPlugin()
]
作者:有勇气的牛排
https://www.couragesteak.com/article/159