webpack.config.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const alias = require('./alias');
  2. const {
  3. outputPath,
  4. nodeModulesPath,
  5. assetsPublicPath,
  6. srcPath,
  7. rootPath,
  8. } = require('./paths');
  9. const plugins = require('./plugins');
  10. const devServer = require('./devServer');
  11. const rules = require('./rules');
  12. const optimization = require('./optimization');
  13. const {resolve} = require('path');
  14. const isProduction = process.env.NODE_ENV === 'production';
  15. const useSourceMap = process.env.ENABLE_SOURCE_MAP === 'true';
  16. const fileName = isProduction
  17. ? 'static/js/[name].[contenthash:8].js'
  18. : 'static/js/[name].js';
  19. const config = {
  20. stats: 'errors-warnings',
  21. target: ['browserslist'],
  22. entry: resolve(srcPath, 'index.tsx'),
  23. devtool: isProduction
  24. ? useSourceMap
  25. ? 'source-map'
  26. : false
  27. : 'cheap-module-source-map',
  28. mode: isProduction ? 'production' : 'development',
  29. performance: false,
  30. infrastructureLogging: {
  31. level: 'none',
  32. },
  33. output: {
  34. path: isProduction ? outputPath : void 0,
  35. filename: fileName,
  36. chunkFilename: fileName,
  37. assetModuleFilename: 'static/assets/[name].[hash][ext]',
  38. clean: true,
  39. publicPath: assetsPublicPath,
  40. },
  41. module: {
  42. rules,
  43. },
  44. cache: {
  45. type: 'filesystem',
  46. cacheDirectory: resolve(rootPath, '.temp-cache'),
  47. },
  48. plugins,
  49. optimization,
  50. resolve: {
  51. modules: ['node_modules', nodeModulesPath],
  52. extensions: ['.jsx', '.js', '.ts', '.tsx', '.json'],
  53. alias,
  54. },
  55. devServer,
  56. };
  57. module.exports = config;