1
0

shared.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 CopyPlugin = require('copy-webpack-plugin');
  8. const extname = require('path-complete-extname');
  9. const { env, settings, themes, output } = require('./configuration');
  10. const rules = require('./rules');
  11. const localePackPaths = require('./generateLocalePacks');
  12. const extensionGlob = `**/*{${settings.extensions.join(',')}}*`;
  13. const entryPath = join(settings.source_path, settings.source_entry_path);
  14. const packPaths = sync(join(entryPath, extensionGlob));
  15. module.exports = {
  16. entry: Object.assign(
  17. packPaths.reduce((map, entry) => {
  18. const localMap = map;
  19. const namespace = relative(join(entryPath), dirname(entry));
  20. localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry);
  21. return localMap;
  22. }, {}),
  23. localePackPaths.reduce((map, entry) => {
  24. const localMap = map;
  25. localMap[basename(entry, extname(entry, extname(entry)))] = resolve(entry);
  26. return localMap;
  27. }, {}),
  28. Object.keys(themes).reduce((themePaths, name) => {
  29. themePaths[name] = resolve(join(settings.source_path, themes[name]));
  30. return themePaths;
  31. }, {}),
  32. ),
  33. output: {
  34. filename: 'js/[name]-[chunkhash].js',
  35. chunkFilename: 'js/[name]-[chunkhash].chunk.js',
  36. hotUpdateChunkFilename: 'js/[id]-[hash].hot-update.js',
  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: false,
  77. entrypoints: true,
  78. writeToDisk: true,
  79. publicPath: true,
  80. }),
  81. new CopyPlugin([
  82. { from: 'node_modules/tesseract.js/dist/worker.min.js', to: 'ocr' },
  83. { from: 'node_modules/tesseract.js-core/tesseract-core.wasm.js', to: 'ocr' },
  84. ]),
  85. ],
  86. resolve: {
  87. extensions: settings.extensions,
  88. modules: [
  89. resolve(settings.source_path),
  90. 'node_modules',
  91. ],
  92. },
  93. resolveLoader: {
  94. modules: ['node_modules'],
  95. },
  96. node: {
  97. // Called by http-link-header in an API we never use, increases
  98. // bundle size unnecessarily
  99. Buffer: false,
  100. },
  101. };