1
0

shared.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. hashFunction: 'sha256',
  37. path: output.path,
  38. publicPath: output.publicPath,
  39. },
  40. optimization: {
  41. runtimeChunk: {
  42. name: 'common',
  43. },
  44. splitChunks: {
  45. cacheGroups: {
  46. default: false,
  47. vendors: false,
  48. common: {
  49. name: 'common',
  50. chunks: 'all',
  51. minChunks: 2,
  52. minSize: 0,
  53. test: /^(?!.*[\\\/]node_modules[\\\/]react-intl[\\\/]).+$/,
  54. },
  55. },
  56. },
  57. occurrenceOrder: true,
  58. },
  59. module: {
  60. rules: Object.keys(rules).map(key => rules[key]),
  61. },
  62. plugins: [
  63. new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
  64. new webpack.NormalModuleReplacementPlugin(
  65. /^history\//, (resource) => {
  66. // temporary fix for https://github.com/ReactTraining/react-router/issues/5576
  67. // to reduce bundle size
  68. resource.request = resource.request.replace(/^history/, 'history/es');
  69. },
  70. ),
  71. new MiniCssExtractPlugin({
  72. filename: 'css/[name]-[contenthash:8].css',
  73. chunkFilename: 'css/[name]-[contenthash:8].chunk.css',
  74. }),
  75. new AssetsManifestPlugin({
  76. integrity: true,
  77. integrityHashes: ['sha256'],
  78. entrypoints: true,
  79. writeToDisk: true,
  80. publicPath: true,
  81. }),
  82. ],
  83. resolve: {
  84. extensions: settings.extensions,
  85. modules: [
  86. resolve(settings.source_path),
  87. 'node_modules',
  88. ],
  89. },
  90. resolveLoader: {
  91. modules: ['node_modules'],
  92. },
  93. node: {
  94. // Called by http-link-header in an API we never use, increases
  95. // bundle size unnecessarily
  96. Buffer: false,
  97. },
  98. };