webpack.config.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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: /\.s?css$/, 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. "react/jsx-runtime": path.join(require.resolve("react"), "..", "jsx-runtime.js")
  78. },
  79. },
  80. externals: {
  81. react: {
  82. root: 'React',
  83. commonjs2: 'react',
  84. commonjs: 'react',
  85. amd: 'react'
  86. },
  87. 'react-dom': {
  88. root: 'ReactDOM',
  89. commonjs2: 'react-dom',
  90. commonjs: 'react-dom',
  91. amd: 'react-dom'
  92. }
  93. }
  94. };
  95. };