webpack.config.ts 1.5 KB

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