webpack.config.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const pkg = require('./package.json')
  2. const path = require('path')
  3. const webpack = require('webpack')
  4. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  5. const TerserPlugin = require('terser-webpack-plugin')
  6. module.exports = (env, argv) => {
  7. const isProd = argv.mode === 'production'
  8. return {
  9. entry: './src/LSPlugin.user.ts',
  10. module: {
  11. rules: [
  12. {
  13. test: /\.tsx?$/,
  14. use: [
  15. {
  16. loader: 'babel-loader'
  17. },
  18. {
  19. loader: 'ts-loader'
  20. }
  21. ],
  22. exclude: /node_modules/,
  23. }
  24. ],
  25. },
  26. resolve: {
  27. extensions: ['.tsx', '.ts', '.js'],
  28. },
  29. optimization: {
  30. minimize: isProd,
  31. minimizer: [
  32. new TerserPlugin()
  33. ]
  34. },
  35. plugins: [
  36. new webpack.ProvidePlugin({
  37. process: 'process/browser',
  38. }),
  39. new webpack.DefinePlugin({
  40. LIB_VERSION: JSON.stringify(pkg.version)
  41. })
  42. // new BundleAnalyzerPlugin()
  43. ],
  44. output: {
  45. library: 'LSPluginEntry',
  46. libraryTarget: 'umd',
  47. filename: 'lsplugin.user.js',
  48. path: path.resolve(__dirname, 'dist')
  49. },
  50. }
  51. }