webpack.config.js 2.1 KB

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