webpack.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const TerserPlugin = require('terser-webpack-plugin');
  4. const DefinePlugin = webpack.DefinePlugin;
  5. const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
  6. const WebpackBarPlugin = require('webpackbar');
  7. const HashedModuleIdsPlugin = webpack.ids.HashedModuleIdsPlugin;
  8. const getBabelConfig = require('./getBabelConfig');
  9. const rootPath = path.join(__dirname, '../..');
  10. module.exports = function ({ minimize }) {
  11. return {
  12. mode: 'production',
  13. bail: true,
  14. devtool: 'source-map',
  15. entry: {
  16. index: ['./index.ts']
  17. },
  18. output: {
  19. filename: minimize ? 'semi-ui.min.js' : 'semi-ui.js',
  20. path: path.join(__dirname, 'dist/umd'),
  21. library: 'SemiUI',
  22. libraryTarget: 'umd'
  23. },
  24. module: {
  25. rules: [
  26. {
  27. test: /\.tsx?$/,
  28. include: [
  29. path.join(rootPath, 'packages/semi-ui'),
  30. path.join(rootPath, 'packages/semi-foundation'),
  31. path.join(rootPath, 'packages/semi-animation'),
  32. path.join(rootPath, 'packages/semi-animation-react')
  33. ],
  34. use: [
  35. {
  36. loader: 'babel-loader',
  37. options: getBabelConfig({ isESM: true })
  38. },
  39. {
  40. loader: 'ts-loader',
  41. options: {
  42. transpileOnly: true,
  43. happyPackMode: false,
  44. appendTsSuffixTo: []
  45. }
  46. }
  47. ]
  48. },
  49. {
  50. test: /semi-icons\/.+\.css$/,
  51. use: 'null-loader'
  52. },
  53. { test: /\.scss$/, use: 'null-loader' },
  54. ]
  55. },
  56. optimization: {
  57. minimize: !!minimize,
  58. minimizer: [new TerserPlugin()]
  59. },
  60. performance: { maxEntrypointSize: 10485760, maxAssetSize: 5242880 },
  61. plugins: [
  62. new DefinePlugin({
  63. 'process.env': { NODE_ENV: '"production"', PUBLIC_URL: undefined }
  64. }),
  65. new CaseSensitivePathsPlugin(),
  66. new WebpackBarPlugin(),
  67. new HashedModuleIdsPlugin()
  68. ],
  69. resolve: {
  70. extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
  71. alias: {
  72. "@douyinfe/semi-foundation": path.resolve(__dirname, "../semi-foundation"),
  73. "@douyinfe/semi-icons": path.resolve(__dirname, "../semi-icons"),
  74. "@douyinfe/semi-illustrations": path.resolve(__dirname, "../semi-illustrations"),
  75. "@douyinfe/semi-animation": path.resolve(__dirname, "../semi-animation"),
  76. "@douyinfe/semi-animation-react": path.resolve(__dirname, "../semi-animation-react")
  77. },
  78. },
  79. externals: {
  80. react: {
  81. root: 'React',
  82. commonjs2: 'react',
  83. commonjs: 'react',
  84. amd: 'react'
  85. },
  86. 'react-dom': {
  87. root: 'ReactDOM',
  88. commonjs2: 'react-dom',
  89. commonjs: 'react-dom',
  90. amd: 'react-dom'
  91. }
  92. }
  93. };
  94. };