You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.4 KiB

7 years ago
  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 { env, settings, core, flavours, output } = require('./configuration.js');
  8. const rules = require('./rules');
  9. const localePacks = require('./generateLocalePacks');
  10. function reducePacks (data, into = {}) {
  11. if (!data.pack) {
  12. return into;
  13. }
  14. Object.keys(data.pack).reduce((map, entry) => {
  15. const pack = data.pack[entry];
  16. if (!pack) {
  17. return map;
  18. }
  19. const packFile = typeof pack === 'string' ? pack : pack.filename;
  20. if (packFile) {
  21. map[data.name ? `flavours/${data.name}/${entry}` : `core/${entry}`] = resolve(data.pack_directory, packFile);
  22. }
  23. return map;
  24. }, into);
  25. if (data.name) {
  26. Object.keys(data.skin).reduce((map, entry) => {
  27. const skin = data.skin[entry];
  28. const skinName = entry;
  29. if (!skin) {
  30. return map;
  31. }
  32. Object.keys(skin).reduce((map, entry) => {
  33. const packFile = skin[entry];
  34. if (!packFile) {
  35. return map;
  36. }
  37. map[`skins/${data.name}/${skinName}/${entry}`] = resolve(packFile);
  38. return map;
  39. }, into);
  40. return map;
  41. }, into);
  42. }
  43. return into;
  44. }
  45. const entries = Object.assign(
  46. { locales: resolve('app', 'javascript', 'locales') },
  47. localePacks,
  48. reducePacks(core),
  49. Object.keys(flavours).reduce((map, entry) => reducePacks(flavours[entry], map), {})
  50. );
  51. module.exports = {
  52. entry: entries,
  53. output: {
  54. filename: 'js/[name]-[chunkhash].js',
  55. chunkFilename: 'js/[name]-[chunkhash].chunk.js',
  56. hotUpdateChunkFilename: 'js/[id]-[hash].hot-update.js',
  57. path: output.path,
  58. publicPath: output.publicPath,
  59. },
  60. optimization: {
  61. runtimeChunk: {
  62. name: 'locales',
  63. },
  64. splitChunks: {
  65. cacheGroups: {
  66. default: false,
  67. vendors: false,
  68. common: {
  69. name: 'common',
  70. chunks (chunk) {
  71. return !(chunk.name in entries);
  72. },
  73. minChunks: 2,
  74. minSize: 0,
  75. test: /^(?!.*[\\\/]node_modules[\\\/]react-intl[\\\/]).+$/,
  76. },
  77. },
  78. },
  79. occurrenceOrder: true,
  80. },
  81. module: {
  82. rules: Object.keys(rules).map(key => rules[key]),
  83. },
  84. plugins: [
  85. new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
  86. new webpack.NormalModuleReplacementPlugin(
  87. /^history\//, (resource) => {
  88. // temporary fix for https://github.com/ReactTraining/react-router/issues/5576
  89. // to reduce bundle size
  90. resource.request = resource.request.replace(/^history/, 'history/es');
  91. }
  92. ),
  93. new MiniCssExtractPlugin({
  94. filename: 'css/[name]-[contenthash:8].css',
  95. chunkFilename: 'css/[name]-[contenthash:8].chunk.css',
  96. }),
  97. new AssetsManifestPlugin({
  98. integrity: false,
  99. entrypoints: true,
  100. writeToDisk: true,
  101. publicPath: true,
  102. }),
  103. ],
  104. resolve: {
  105. extensions: settings.extensions,
  106. modules: [
  107. resolve(settings.source_path),
  108. 'node_modules',
  109. ],
  110. },
  111. resolveLoader: {
  112. modules: ['node_modules'],
  113. },
  114. node: {
  115. // Called by http-link-header in an API we never use, increases
  116. // bundle size unnecessarily
  117. Buffer: false,
  118. },
  119. };