- 升级 babel 相关依赖至 ^7.26.0,配置按需引入 core-js polyfill - 升级 webpack 5.70.0 → 5.97.1,webpack-cli 4.9.2 → 5.1.4 - 升级 css-loader、postcss-loader、less-loader 等至最新版本 - 移除废弃的 file-loader/url-loader,改用 webpack5 内置 asset modules - 移除 babel-polyfill 和 leancloud-storage,添加 @babel/runtime 和 core-js - 升级 vue 2.6.14 → 2.7.16,axios 1.13.6 → 1.8.4 - 添加 browserslist 配置 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
84 lines
2.3 KiB
JavaScript
84 lines
2.3 KiB
JavaScript
const TerserPlugin = require('terser-webpack-plugin')
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
|
|
|
|
|
|
const htmlPluginConfig = {
|
|
inject: false,
|
|
cache: false,
|
|
minify: {
|
|
collapseInlineTagWhitespace: true,
|
|
collapseWhitespace: true,
|
|
minifyJS:true
|
|
}
|
|
}
|
|
|
|
module.exports = function(env, argv) {
|
|
// 是否是生产环境
|
|
let isProd = argv.mode === 'production'
|
|
return {
|
|
optimization: {
|
|
minimizer: [new TerserPlugin({
|
|
extractComments: false,
|
|
})]
|
|
},
|
|
entry: {
|
|
main: './source-src/js/main.js',
|
|
slider: './source-src/js/slider.js',
|
|
mobile: './source-src/js/mobile.js',
|
|
viewer: './source-src/js/viewer.js'
|
|
},
|
|
output: {
|
|
publicPath: '/',
|
|
path: __dirname + '/source',
|
|
filename: isProd ? 'js/[name].[chunkhash].js' : 'js/[name].js'
|
|
},
|
|
module: {
|
|
rules: [{
|
|
test: /\.js$/,
|
|
use: 'babel-loader',
|
|
exclude: /node_modules/
|
|
},{
|
|
test: /\.less$/,
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'less-loader']
|
|
},{
|
|
test: /\.css$/,
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader']
|
|
},{
|
|
test: /\.(png|jpe?g|gif|ico)$/,
|
|
type: 'asset/resource',
|
|
generator: {
|
|
filename: 'images/[name].[contenthash:6][ext]'
|
|
}
|
|
},{
|
|
test: /\.(svg|eot|ttf|woff2?|otf)$/,
|
|
type: 'asset/resource',
|
|
generator: {
|
|
filename: 'fonts/[name].[contenthash:6][ext]'
|
|
}
|
|
}
|
|
]
|
|
},
|
|
plugins: [
|
|
new HtmlWebpackPlugin(Object.assign({
|
|
template: './source-src/template/script.html',
|
|
filename: '../layout/_partial/script.ejs'
|
|
}, htmlPluginConfig)),
|
|
new HtmlWebpackPlugin(Object.assign({
|
|
template: './source-src/template/css.html',
|
|
filename: '../layout/_partial/css.ejs'
|
|
}, htmlPluginConfig)),
|
|
new CleanWebpackPlugin({
|
|
cleanOnceBeforeBuildPatterns: ['js/*','css/*','fonts/*','images/*'],
|
|
verbose: true,
|
|
dry: false,
|
|
}),
|
|
new MiniCssExtractPlugin({
|
|
filename: 'css/[name].[contenthash:6].css'
|
|
})
|
|
],
|
|
mode: argv.mode,
|
|
watch: !isProd
|
|
}
|
|
} |