1
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
const path = require('path')
|
||||
const webpack = require('webpack')
|
||||
const { VueLoaderPlugin } = require('vue-loader')
|
||||
const TerserPlugin = require('terser-webpack-plugin')
|
||||
|
||||
module.exports = {
|
||||
mode: 'production', // 明确指定生产模式
|
||||
target: 'web', // 明确指定浏览器环境
|
||||
entry: './src/index.js',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
@@ -13,6 +15,7 @@ module.exports = {
|
||||
libraryTarget: 'umd',
|
||||
libraryExport: 'default',
|
||||
globalObject: 'typeof self !== \'undefined\' ? self : this',
|
||||
umdNamedDefine: true, // 为 UMD 模块添加名称
|
||||
clean: true // 构建前清理 dist 目录
|
||||
},
|
||||
externals: {
|
||||
@@ -56,7 +59,26 @@ module.exports = {
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'babel-loader',
|
||||
exclude: /node_modules/
|
||||
exclude: /node_modules/,
|
||||
options: {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
modules: 'auto', // 修改为 auto,让 webpack 自动处理模块格式
|
||||
targets: {
|
||||
browsers: ['>1%', 'last 2 versions', 'not ie <= 8']
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
'@vue/babel-preset-jsx',
|
||||
{
|
||||
injectH: true
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
@@ -146,7 +168,7 @@ module.exports = {
|
||||
optimization: {
|
||||
minimize: true,
|
||||
minimizer: [
|
||||
new (require('terser-webpack-plugin'))({
|
||||
new TerserPlugin({
|
||||
terserOptions: {
|
||||
format: {
|
||||
comments: /^!|@preserve|@license|@cc_on|admin-framework|作者/i // 保留特殊注释
|
||||
|
||||
Reference in New Issue
Block a user