[JavaScript] 纯文本查看 复制代码
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const OptimizeCssAssetsWebpackPlugin=require('optimize-css-assets-webpack-plugin')
module.exports={
mode: 'development',//生产模式上线production 开发模式 development 加空格
entry: './src/index.js',//单入口配置入口文件
output: {//输出位置
path: path.resolve(__dirname, 'dist'),//输出目录
filename: "[name].js",//指定输出文件名
},
module: {
rules: [
// { test: /\.css$/, use: ['style-loader','css-loader'] },
{ test: /\.css$/, use: [MiniCssExtractPlugin.loader,'css-loader','postcss-loader'] },
{ test: /\.less$/, use: [MiniCssExtractPlugin.loader,'css-loader','less-loader'] },
{ test: /\.scss$/, use: [MiniCssExtractPlugin.loader,'css-loader','sass-loader'] },
// { test:/\.(png|jpg|gif|jpeg)$/,use:['url-loader',{loader:'file-loader',options:{}}]}
{ test: /\.(png|jpg|gif|jpeg)$/,loader:'url-loader',options:{
publicPath: './images/',//
outputPath: 'images/',//指定图片路径
limit: 1028 * 8,//1028字节是1kb
name:'[name][hash:10].[ext]',
esModule:false
}},
{
test:/\.html$/,
loader:'html-loader',
options:{
esModule:false
}
}
],//打包css 和less
},
plugins:[//插件 范围更广的规则打包html
new HtmlWebpackPlugin({//几个页面new几个
template:'./src/index.html',
filename:'index.html',//指定打包文件名称
}),//默认会创建一个空 的 自动引入(css/js)
new MiniCssExtractPlugin({//生成单独的css
}),
new OptimizeCssAssetsWebpackPlugin()
]
}