shared.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Note: You must restart bin/webpack-dev-server for changes to take effect
  2. const { basename, dirname, join, relative, resolve } = require('path');
  3. const CircularDependencyPlugin = require('circular-dependency-plugin');
  4. const { sync } = require('glob');
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6. const extname = require('path-complete-extname');
  7. const webpack = require('webpack');
  8. const AssetsManifestPlugin = require('webpack-assets-manifest');
  9. const { env, settings, themes, output } = require('./configuration');
  10. const rules = require('./rules');
  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. Object.keys(themes).reduce((themePaths, name) => {
  23. themePaths[name] = resolve(join(settings.source_path, themes[name]));
  24. return themePaths;
  25. }, {}),
  26. ),
  27. output: {
  28. filename: 'js/[name]-[chunkhash].js',
  29. chunkFilename: 'js/[name]-[chunkhash].chunk.js',
  30. hotUpdateChunkFilename: 'js/[id]-[hash].hot-update.js',
  31. hashFunction: 'sha256',
  32. crossOriginLoading: 'anonymous',
  33. path: output.path,
  34. publicPath: output.publicPath,
  35. },
  36. optimization: {
  37. runtimeChunk: {
  38. name: 'common',
  39. },
  40. splitChunks: {
  41. cacheGroups: {
  42. default: false,
  43. vendors: false,
  44. common: {
  45. name: 'common',
  46. chunks: 'all',
  47. minChunks: 2,
  48. minSize: 0,
  49. test: /^(?!.*[\\/]node_modules[\\/]react-intl[\\/]).+$/,
  50. },
  51. },
  52. },
  53. occurrenceOrder: true,
  54. },
  55. module: {
  56. rules: Object.keys(rules).map(key => rules[key]),
  57. strictExportPresence: true,
  58. },
  59. plugins: [
  60. new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
  61. new webpack.NormalModuleReplacementPlugin(
  62. /^history\//, (resource) => {
  63. // temporary fix for https://github.com/ReactTraining/react-router/issues/5576
  64. // to reduce bundle size
  65. resource.request = resource.request.replace(/^history/, 'history/es');
  66. },
  67. ),
  68. new MiniCssExtractPlugin({
  69. filename: 'css/[name]-[contenthash:8].css',
  70. chunkFilename: 'css/[name]-[contenthash:8].chunk.css',
  71. }),
  72. new AssetsManifestPlugin({
  73. integrity: true,
  74. integrityHashes: ['sha256'],
  75. entrypoints: true,
  76. writeToDisk: true,
  77. publicPath: true,
  78. }),
  79. new CircularDependencyPlugin({
  80. failOnError: 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. };