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: 'js/[name].umd.js', library: 'ZhichengUI', libraryTarget: 'umd', umdNamedDefine: true, globalObject: `(typeof self !== 'undefined' ? self : this)` }, resolve: { alias: { '@': path.resolve(__dirname, './packages'), // 确保别名指向正确 '@assets': path.resolve(__dirname, './packages/assets') } }, 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'), sassOptions: { // fibers: require('fibers'), // 不再需要 fibers:false, outputStyle: 'compressed', quietDeps: true // 忽略警告 } } } ] }, // { // 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, publicPath: '../' } }] } ] }, plugins: [ new VueLoaderPlugin(), new MiniCssExtractPlugin({ filename: 'css/[name].css' // 输出到dist/css/ }) ], optimization: { splitChunks: false, minimize: false // 临时关闭压缩 }, externals: { vue: { root: 'Vue', commonjs: 'vue', commonjs2: 'vue', amd: 'vue' } }, stats: { warningsFilter: () => true // 过滤所有警告 } }