const path = require('path') const MiniCssExtractPlugin = require('mini-css-extract-plugin') const { VueLoaderPlugin } = require('vue-loader') module.exports = { mode: 'production', stats: 'verbose', entry: { 'zhicheng-components': './packages/index.js' }, output: { path: path.resolve(__dirname, '../dist'), filename: '[name].umd.js', library: 'ZhichengUI', libraryTarget: 'umd', umdNamedDefine: true, globalObject: `(typeof self !== 'undefined' ? self : this)` }, resolve: { alias: { '@': path.resolve(__dirname, './packages') // 确保别名指向正确 } }, module: { rules: [ { test: /\.vue$/, loader: 'vue-loader', options: { compilerOptions: { preserveWhitespace: false } } }, { test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] // 替换style-loader }, { test: /\.scss$/, use: [MiniCssExtractPlugin.loader, 'css-loader', { loader: 'sass-loader', options: { implementation: require('sass') // 显式指定 sass } }] }, { test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i, use: [{ loader: 'url-loader', options: { limit: 4096, name: 'fonts/[name].[hash:8].[ext]', esModule: false, publicPath: '../', // 关键:修正 CSS 中的引用路径 } }] }, { test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, use: [{ loader: 'url-loader', options: { limit: 4096, name: 'img/[name].[hash:8].[ext]', esModule: false } }] } ] }, plugins: [ new VueLoaderPlugin(), new MiniCssExtractPlugin({ filename: 'css/[name].css' // 输出到dist/css/ }) ], optimization: { splitChunks: false }, externals: { vue: { root: 'Vue', commonjs: 'vue', commonjs2: 'vue', amd: 'vue' } } }