var path = require('path'); var webpack = require('webpack'); const WebpackMerge = require('webpack-merge'); const baseConfig = require('./webpack.base.js'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const TerserPlugin = require('terser-webpack-plugin'); const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); module.exports = WebpackMerge.merge(baseConfig,{ mode: 'production', // 发布组件 entry: './packages/index.js', output: { path: path.resolve(__dirname, './dist'), publicPath: '/dist/', filename: 'pc-component-v3.js', // library: { // type: 'module', // }, library: 'pc-component-v3', libraryTarget: 'umd', //「devtool 中模块」的文件名模板(用于冲突) umdNamedDefine: false, }, // experiments: { // outputModule: true, // }, optimization: { minimize: false, // 压缩 bundle minimizer: [ new TerserPlugin({ parallel: true, terserOptions: { // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions format: { // 保留 webpackIgnore: true 的注解 comments: /(\s*webpackIgnore)/i, }, }, }), ], }, devtool: 'source-map', plugins: (module.exports.plugins || []).concat([ // CSS 提取 new MiniCssExtractPlugin({ filename: 'pc-component-v3.css', }), // 打包分析插件 // https://github.com/webpack-contrib/webpack-bundle-analyzer //下面是该插件的默认配置,一般无需修改 new BundleAnalyzerPlugin({ // 可以是`server`,`static`或`disabled`。 // 在`server`模式下,分析器将启动HTTP服务器来显示软件包报告。 // 在“静态”模式下,会生成带有报告的单个HTML文件。 // 在`disabled`模式下,你可以使用这个插件来将`generateStatsFile`设置为`true`来生成Webpack Stats JSON文件。 analyzerMode: 'server', // 将在“服务器”模式下使用的主机启动HTTP服务器。 analyzerHost: '127.0.0.1', // 将在“服务器”模式下使用的端口启动HTTP服务器。 analyzerPort: 8888, // 路径捆绑,将在`static`模式下生成的报告文件。 // 相对于捆绑输出目录。 reportFilename: 'report.html', // 模块大小默认显示在报告中。 // 应该是`stat`,`parsed`或者`gzip`中的一个。 // 有关更多信息,请参见“定义”一节。 defaultSizes: 'parsed', // 在默认浏览器中自动打开报告 openAnalyzer: true, // 如果为true,则Webpack Stats JSON文件将在bundle输出目录中生成 generateStatsFile: false, // 如果`generateStatsFile`为`true`,将会生成Webpack Stats JSON文件的名字。 // 相对于捆绑输出目录。 statsFilename: 'stats.json', // stats.toJson()方法的选项。 // 例如,您可以使用`source:false`选项排除统计文件中模块的来源。 // 在这里查看更多选项:https: //github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21 statsOptions: null, logLevel: 'info', // 日志级别。可以是'信息','警告','错误'或'沉默'。 }), ]), // 不把第三方库打包到bundle中 externals: { jQuery: 'window.$', jquery: 'window.$', $: 'window.$', 'bootstrap': 'bootstrap', 'dayjs': 'dayjs', // 不将vue代码打包进我们的组件库代码中,如果将vue代码打包进组件库中则会报错 'vue': 'vue', 'vue-i18n': 'vue-i18n', 'vue-router': 'vue-router', 'v-tooltip': 'v-tooltip', 'vuedraggable': 'vuedraggable', 'lowcode': 'lowcode', 'ant-design-vue': 'ant-design-vue', }, });