webpack.config.js 803 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const path = require('path');
  2. const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  3. const TerserPlugin = require('terser-webpack-plugin');
  4. module.exports = {
  5. entry: './src/index.js',
  6. output: {
  7. path: path.resolve(__dirname, 'dist'),
  8. filename: 'main.js',
  9. library: {
  10. name: 'UtmTracker',
  11. type: 'umd',
  12. },
  13. globalObject: 'this',
  14. // 添加ES模块支持
  15. libraryExport: 'default',
  16. },
  17. mode: 'production',
  18. module: {
  19. rules: [
  20. {
  21. test: /\.js$/,
  22. exclude: /node_modules/,
  23. use: {
  24. loader: 'babel-loader',
  25. options: {
  26. presets: ['@babel/preset-env'],
  27. },
  28. },
  29. },
  30. ],
  31. },
  32. optimization: {
  33. minimizer: [new TerserPlugin()],
  34. },
  35. plugins: [new CleanWebpackPlugin()],
  36. };