shared.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Note: You must restart bin/webpack-dev-server for changes to take effect
  2. const webpack = require('webpack');
  3. const { basename, dirname, join, relative, resolve } = require('path');
  4. const { sync } = require('glob');
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6. const AssetsManifestPlugin = require('webpack-assets-manifest');
  7. const extname = require('path-complete-extname');
  8. const { env, settings, themes, output } = require('./configuration');
  9. const rules = require('./rules');
  10. const localePackPaths = require('./generateLocalePacks');
  11. const extensionGlob = `**/*{${settings.extensions.join(',')}}*`;
  12. const entryPath = join(settings.source_path, settings.source_entry_path);
  13. const packPaths = sync(join(entryPath, extensionGlob));
  14. module.exports = {
  15. entry: Object.assign(
  16. packPaths.reduce((map, entry) => {
  17. const localMap = map;
  18. const namespace = relative(join(entryPath), dirname(entry));
  19. localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry);
  20. return localMap;
  21. }, {}),
  22. localePackPaths.reduce((map, entry) => {
  23. const localMap = map;
  24. localMap[basename(entry, extname(entry, extname(entry)))] = resolve(entry);
  25. return localMap;
  26. }, {}),
  27. Object.keys(themes).reduce((themePaths, name) => {
  28. themePaths[name] = resolve(join(settings.source_path, themes[name]));
  29. return themePaths;
  30. }, {})
  31. ),
  32. output: {
  33. filename: 'js/[name]-[chunkhash].js',
  34. chunkFilename: 'js/[name]-[chunkhash].chunk.js',
  35. hotUpdateChunkFilename: 'js/[id]-[hash].hot-update.js',
  36. path: output.path,
  37. publicPath: output.publicPath,
  38. },
  39. optimization: {
  40. runtimeChunk: {
  41. name: 'common',
  42. },
  43. splitChunks: {
  44. cacheGroups: {
  45. default: false,
  46. vendors: false,
  47. common: {
  48. name: 'common',
  49. chunks: 'all',
  50. minChunks: 2,
  51. minSize: 0,
  52. test: /^(?!.*[\\\/]node_modules[\\\/]react-intl[\\\/]).+$/,
  53. },
  54. },
  55. },
  56. occurrenceOrder: true,
  57. },
  58. module: {
  59. rules: Object.keys(rules).map(key => rules[key]),
  60. },
  61. plugins: [
  62. new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
  63. new webpack.NormalModuleReplacementPlugin(
  64. /^history\//, (resource) => {
  65. // temporary fix for https://github.com/ReactTraining/react-router/issues/5576
  66. // to reduce bundle size
  67. resource.request = resource.request.replace(/^history/, 'history/es');
  68. }
  69. ),
  70. new MiniCssExtractPlugin({
  71. filename: 'css/[name]-[contenthash:8].css',
  72. chunkFilename: 'css/[name]-[contenthash:8].chunk.css',
  73. }),
  74. new AssetsManifestPlugin({
  75. integrity: false,
  76. entrypoints: true,
  77. writeToDisk: true,
  78. publicPath: true,
  79. }),
  80. ],
  81. resolve: {
  82. extensions: settings.extensions,
  83. modules: [
  84. resolve(settings.source_path),
  85. 'node_modules',
  86. ],
  87. },
  88. resolveLoader: {
  89. modules: ['node_modules'],
  90. },
  91. node: {
  92. // Called by http-link-header in an API we never use, increases
  93. // bundle size unnecessarily
  94. Buffer: false,
  95. },
  96. };