|
@@ -1,20 +1,71 @@
|
|
|
const path = require('path');
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
+const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
+const isDev = process.env.NODE_ENV !== 'production';
|
|
|
|
|
|
module.exports = {
|
|
|
entry: {
|
|
|
index: path.join(__dirname, '../src/main.js'),
|
|
|
},
|
|
|
output: {
|
|
|
- filename: '[name].bundle.[chunkhash].js',
|
|
|
+ filename: isDev ? '[name].bundle.[chunkhash].js' : '[name].js',
|
|
|
path: path.resolve(__dirname, '../dist'),
|
|
|
clean: true, // 每一次打包前清空dist文件夹
|
|
|
},
|
|
|
+ module: {
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ test: /\.(png|svg|jpeg|gif)$/i,
|
|
|
+ include: path.join(__dirname, '../src'),
|
|
|
+ type: 'asset/resource',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ test: /\.(woff|woff2|eot|ttf|otf)$/i,
|
|
|
+ include: [path.join(__dirname, '../src')],
|
|
|
+ type: 'asset/resource',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ test: /\.(le|c)ss$/i,
|
|
|
+ include: [path.join(__dirname, '../src')],
|
|
|
+ use: [
|
|
|
+ {
|
|
|
+ loader: MiniCssExtractPlugin.loader,
|
|
|
+ options: {
|
|
|
+ publicPath: '../',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ loader: 'css-loader',
|
|
|
+ options: {
|
|
|
+ esModule: true,
|
|
|
+ modules: {
|
|
|
+ namedExport: true,
|
|
|
+ localIdentName: '[local]',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ loader: 'postcss-loader',
|
|
|
+ options: {
|
|
|
+ postcssOptions: {
|
|
|
+ plugins: [['postcss-preset-env']],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'less-loader',
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
plugins: [
|
|
|
new HtmlWebpackPlugin({
|
|
|
title: 'Vue App',
|
|
|
favicon: path.join(__dirname, '../public/favicon.ico'),
|
|
|
template: path.join(__dirname, '../public/index.html'),
|
|
|
}),
|
|
|
+ new MiniCssExtractPlugin({
|
|
|
+ filename: isDev ? '[name].[contenthash].css' : '[name].css',
|
|
|
+ chunkFilename: isDev ? '[id].[contenthash].css' : '[id].css',
|
|
|
+ }),
|
|
|
],
|
|
|
};
|