webpack.config.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. publicPath: assetsPublicPath,
  39. },
  40. module: {
  41. rules,
  42. },
  43. cache: {
  44. type: 'filesystem',
  45. cacheDirectory: resolve(rootPath, '.temp-cache'),
  46. },
  47. plugins,
  48. optimization,
  49. resolve: {
  50. modules: ['node_modules', nodeModulesPath],
  51. extensions: ['.jsx', '.js', '.ts', '.tsx', '.json'],
  52. alias,
  53. },
  54. devServer,
  55. };
  56. module.exports = config;