webpack.lib.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. var path = require('path');
  2. var webpack = require('webpack');
  3. const WebpackMerge = require('webpack-merge');
  4. const baseConfig = require('./webpack.base.js');
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6. const TerserPlugin = require('terser-webpack-plugin');
  7. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
  8. const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  9. const CopyPlugin = require("copy-webpack-plugin");
  10. module.exports = WebpackMerge.merge(baseConfig,{
  11. mode: 'production',
  12. // 发布组件
  13. entry: './src/index.js',
  14. output: {
  15. path: path.resolve(__dirname, './dist'),
  16. publicPath: '/dist/',
  17. filename: 'client-eam-v5.js',
  18. // library: {
  19. // type: 'module',
  20. // },
  21. library: 'client-eam-v5',
  22. libraryTarget: 'umd',
  23. //「devtool 中模块」的文件名模板(用于冲突)
  24. umdNamedDefine: false,
  25. },
  26. // experiments: {
  27. // outputModule: true,
  28. // },
  29. optimization: {
  30. minimize: false, // 压缩 bundle
  31. minimizer: [
  32. new TerserPlugin({
  33. parallel: true,
  34. terserOptions: {
  35. // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
  36. format: {
  37. // 保留 webpackIgnore: true 的注解
  38. comments: /(\s*webpackIgnore)/i,
  39. },
  40. },
  41. }),
  42. ],
  43. },
  44. devtool: 'source-map',
  45. plugins: (module.exports.plugins || []).concat([
  46. // 清除dist文件夹
  47. new CleanWebpackPlugin(),
  48. // CSS 提取
  49. new MiniCssExtractPlugin({
  50. filename: 'client-eam-v5.css',
  51. }),
  52. // 打包分析插件
  53. // https://github.com/webpack-contrib/webpack-bundle-analyzer
  54. //下面是该插件的默认配置,一般无需修改
  55. new BundleAnalyzerPlugin({
  56. // 可以是`server`,`static`或`disabled`。
  57. // 在`server`模式下,分析器将启动HTTP服务器来显示软件包报告。
  58. // 在“静态”模式下,会生成带有报告的单个HTML文件。
  59. // 在`disabled`模式下,你可以使用这个插件来将`generateStatsFile`设置为`true`来生成Webpack Stats JSON文件。
  60. analyzerMode: 'server',
  61. // 将在“服务器”模式下使用的主机启动HTTP服务器。
  62. analyzerHost: '127.0.0.1',
  63. // 将在“服务器”模式下使用的端口启动HTTP服务器。
  64. analyzerPort: 8888,
  65. // 路径捆绑,将在`static`模式下生成的报告文件。
  66. // 相对于捆绑输出目录。
  67. reportFilename: 'report.html',
  68. // 模块大小默认显示在报告中。
  69. // 应该是`stat`,`parsed`或者`gzip`中的一个。
  70. // 有关更多信息,请参见“定义”一节。
  71. defaultSizes: 'parsed',
  72. // 在默认浏览器中自动打开报告
  73. openAnalyzer: true,
  74. // 如果为true,则Webpack Stats JSON文件将在bundle输出目录中生成
  75. generateStatsFile: false,
  76. // 如果`generateStatsFile`为`true`,将会生成Webpack Stats JSON文件的名字。
  77. // 相对于捆绑输出目录。
  78. statsFilename: 'stats.json',
  79. // stats.toJson()方法的选项。
  80. // 例如,您可以使用`source:false`选项排除统计文件中模块的来源。
  81. // 在这里查看更多选项:https: //github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
  82. statsOptions: null,
  83. logLevel: 'info', // 日志级别。可以是'信息','警告','错误'或'沉默'。
  84. }),
  85. // new CopyPlugin({
  86. // patterns: [
  87. // {
  88. // noErrorOnMissing: false, // 默认false,不会对丢失的文件产生错误
  89. // force: false, // 默认false,覆盖已经存在的文件
  90. // priority: 0, // 允许指定复制具有相同目标名称的文件的优先级
  91. // from: path.resolve(__dirname, "src/assets/style"), // 拷贝来源
  92. // to: path.resolve(__dirname, "dist/assets"), // 拷贝到的位置
  93. // toType: "dir", // 目录dir、文件file或模板template
  94. // }
  95. // ],
  96. // options: {
  97. // concurrency: 100, // 同时请求fs的数量限制
  98. // },
  99. // }),
  100. ]),
  101. // 不把第三方库打包到bundle中
  102. externals: {
  103. "ant-design-vue": "ant-design-vue",
  104. "dayjs": "dayjs",
  105. "pc-component-v3": "pc-component-v3",
  106. "v-tooltip": "v-tooltip",
  107. "vue-select": "vue-select",
  108. 'jquery': "jquery",
  109. 'bootstrap': 'bootstrap',
  110. 'BootstrapDialog': 'BootstrapDialog',
  111. 'vue': 'vue',
  112. 'vue-i18n': 'vue-i18n',
  113. 'vue-router': 'vue-router',
  114. 'vuex': 'vuex',
  115. },
  116. });