webpack.config.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.HashedModuleIdsPlugin;
  8. const babelConfig = require('./babel.config');
  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. ],
  32. use: [
  33. {
  34. loader: 'babel-loader',
  35. options: babelConfig
  36. },
  37. {
  38. loader: 'ts-loader',
  39. options: {
  40. transpileOnly: true,
  41. happyPackMode: false,
  42. appendTsSuffixTo: []
  43. }
  44. }
  45. ]
  46. },
  47. {
  48. test: /semi-icons\/.+\.css$/,
  49. loaders: 'null-loader'
  50. },
  51. { test: /\.scss$/, loaders: 'null-loader' },
  52. ]
  53. },
  54. optimization: {
  55. minimize: !!minimize,
  56. minimizer: [new TerserPlugin()]
  57. },
  58. performance: { maxEntrypointSize: 10485760, maxAssetSize: 5242880 },
  59. plugins: [
  60. new DefinePlugin({
  61. 'process.env': { NODE_ENV: '"production"', PUBLIC_URL: undefined }
  62. }),
  63. new CaseSensitivePathsPlugin(),
  64. new WebpackBarPlugin(),
  65. new HashedModuleIdsPlugin()
  66. ],
  67. resolve: {
  68. extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
  69. },
  70. externals: {
  71. react: {
  72. root: 'React',
  73. commonjs2: 'react',
  74. commonjs: 'react',
  75. amd: 'react'
  76. },
  77. 'react-dom': {
  78. root: 'ReactDOM',
  79. commonjs2: 'react-dom',
  80. commonjs: 'react-dom',
  81. amd: 'react-dom'
  82. }
  83. }
  84. };
  85. };