1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const htmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/app.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'static/[name]-[chunkhash:5].js'
},
mode: 'development',
module: {
rules: [
{ test: /\.(png|svg|jpg|gif)$/, use: ['file-loader'] },
{ test: /\.css$/,
use: [ // ['file-loader']
{ loader: 'style-loader',options: {} },
{ loader: 'css-loader',options: { modules: true } },
{ loader: 'postcss-loader',options: {} }
]
}, // 仅有style-loader样式不生效
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader',include: path.resolve(__dirname, 'src') },
{ test: /\.(sa|sc)ss$/, use: ['style-loader','css-loader','postcss-loader','sass-loader'] }
]
},
plugins: [
new CleanWebpackPlugin(),
new htmlWebpackPlugin({
title: 'webpack4 test',
template: './public/index.html',// 需要注入到输出文件的模板
filename: 'index.html', // 注意这里的目录是dist目录,也就是在dist文件夹下生成index.html
meta: {viewport: '},//生成的html文件是否产生的meta标签内容
// hash: true,// 产生的css,js文件是否hash
})
],
devServer: {
contentBase: path.join(__dirname, "public"), // default configs
// // host: "0.0.0.0", 默认值
// open: true, //已在pakage.json脚本中配置
port: 8099,
historyApiFallBack: true, // 使用H5 history API时,任意404不会被替代为index.html(官)
},
// devtool: 'source-map', // 打包时生成调试的完整.map文件,但同时影响打包速度!
stats: { // 以下配置是为了避免出现 Entrypoint undefined = index.html
children: false,
}
} |