webpack.config.js 1.4 KB

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