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.

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