htmlwebpackplugin主要是为了能够自动将bundle.js文件自动注入到html文件中,这样的话,我就可以不用再html中手动输入引入路径,也可以避免因为项目位置发生变得导致引入路径发生错误的问题。
const path = require('path');
const webpack = require('webpack');
const FooterPlugin = require('./plugin/FooterPlugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: 'development',
entry: './src/index.js',
// devtool: 'source-map',
// devtool: 'eval',
// devtool: 'eval-source-map',
output: {
path: path.resolve(__dirname, './dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.css$/,
use: ['css-loader']
},
// {
// test: /\.jsx$/,
// use: [path.resolve(__dirname, './loader/immoc-loader.js')]
// }
]
},
plugins: [
new webpack.BannerPlugin({
banner: '欢迎'
}),
// new FooterPlugin({
// banner: '欢迎'
// }),
new HtmlWebpackPlugin(),
new webpack.SourceMapDevToolPlugin({
// fileName 这个属性是必传的
filename: '[file].map', // 生成的 source map 文件名
noSources: true // 禁用源代码映射
})
]
}