config-overrides.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const {
  2. override,
  3. fixBabelImports,
  4. addLessLoader,
  5. addWebpackAlias,
  6. overrideDevServer,
  7. } = require(
  8. 'customize-cra')
  9. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  10. const path = require('path')
  11. //执行npm run build不产生map文件
  12. process.env.GENERATE_SOURCEMAP = 'false'
  13. const isEnvProduction = process.env.NODE_ENV === 'production'
  14. const addCompression = () => config => {
  15. if (isEnvProduction) {
  16. config.plugins.push(
  17. // gzip压缩
  18. new CompressionWebpackPlugin({
  19. test: /\.(css|js)$/,
  20. // 只处理比1kb大的资源
  21. threshold: 1024,
  22. // 只处理压缩率低于90%的文件
  23. minRatio: 0.9,
  24. }),
  25. )
  26. }
  27. return config
  28. }
  29. /**
  30. * 解决react router 路由刷新404问题
  31. * @returns {function(*): {historyApiFallback: boolean}}
  32. */
  33. const devServerConfig = () => config => {
  34. return {
  35. ...config,
  36. historyApiFallback: true,
  37. }
  38. }
  39. module.exports = {
  40. webpack: override(
  41. fixBabelImports('import-antd', {
  42. libraryName: 'antd',
  43. libraryDirectory: 'es',
  44. style: true,
  45. }),
  46. fixBabelImports('import-ant-mobile', {
  47. libraryName: 'antd-mobile',
  48. libraryDirectory: 'lib',
  49. style: true,
  50. }),
  51. addLessLoader({
  52. javascriptEnabled: true,
  53. modifyVars: { '@primary-color': '#1DA57A' },
  54. }),
  55. addCompression(),
  56. addWebpackAlias({
  57. '@': path.join(__dirname, 'src'),
  58. }),
  59. ),
  60. // devServer: overrideDevServer(
  61. // devServerConfig(),
  62. // ),
  63. }