webpack.config.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const TerserPlugin = require('terser-webpack-plugin');
  4. const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
  5. const babelConfig = require('./babel.config');
  6. module.exports = function getWebpackConfig({ minimize }){
  7. return {
  8. mode: 'production',
  9. bail: true,
  10. devtool: 'source-map',
  11. entry: {
  12. index: ['./src/index.ts']
  13. },
  14. output: {
  15. filename: minimize ? 'umd/semi-illustrations.min.js' : 'umd/semi-illustrations.js',
  16. path: path.join(__dirname, 'dist'),
  17. library: 'SemiIllustrations',
  18. libraryTarget: 'umd'
  19. },
  20. module: {
  21. rules: [
  22. {
  23. test: /\.tsx?$/,
  24. include: [
  25. path.resolve(__dirname, 'src'),
  26. ],
  27. use: [
  28. {
  29. loader: 'babel-loader',
  30. options: babelConfig
  31. },
  32. {
  33. loader: 'ts-loader',
  34. options: {
  35. transpileOnly: true,
  36. happyPackMode: false,
  37. appendTsSuffixTo: []
  38. }
  39. }
  40. ]
  41. }
  42. ]
  43. },
  44. optimization: {
  45. minimize: !!minimize,
  46. minimizer: [new TerserPlugin()]
  47. },
  48. performance: { maxEntrypointSize: 10485760, maxAssetSize: 5242880 },
  49. plugins: [
  50. new webpack.DefinePlugin({
  51. 'process.env': { NODE_ENV: '"production"' }
  52. }),
  53. new CaseSensitivePathsPlugin(),
  54. new webpack.HashedModuleIdsPlugin(),
  55. ],
  56. resolve: {
  57. extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
  58. },
  59. externals: {
  60. react: {
  61. root: 'React',
  62. commonjs2: 'react',
  63. commonjs: 'react',
  64. amd: 'react'
  65. }
  66. }
  67. };
  68. };