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.

106 lines
2.9 KiB

7 years ago
7 years ago
  1. // Note: You must restart bin/webpack-dev-server for changes to take effect
  2. const webpack = require('webpack');
  3. const { join, resolve } = require('path');
  4. const { sync } = require('glob');
  5. const ExtractTextPlugin = require('extract-text-webpack-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. module.exports = {
  45. entry: 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. output: {
  52. filename: '[name].js',
  53. chunkFilename: '[name].js',
  54. path: output.path,
  55. publicPath: output.publicPath,
  56. },
  57. module: {
  58. rules: sync(join(loadersDir, '*.js')).map(loader => require(loader)),
  59. },
  60. plugins: [
  61. new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
  62. new webpack.NormalModuleReplacementPlugin(
  63. /^history\//, (resource) => {
  64. // temporary fix for https://github.com/ReactTraining/react-router/issues/5576
  65. // to reduce bundle size
  66. resource.request = resource.request.replace(/^history/, 'history/es');
  67. }
  68. ),
  69. new ExtractTextPlugin({
  70. filename: env.NODE_ENV === 'production' ? '[name]-[contenthash].css' : '[name].css',
  71. allChunks: true,
  72. }),
  73. new ManifestPlugin({
  74. publicPath: output.publicPath,
  75. writeToFileEmit: true,
  76. }),
  77. new webpack.optimize.CommonsChunkPlugin({
  78. name: 'locales',
  79. minChunks: Infinity, // It doesn't make sense to use common chunks with multiple frontend support.
  80. }),
  81. ],
  82. resolve: {
  83. extensions: settings.extensions,
  84. modules: [
  85. resolve(settings.source_path),
  86. 'node_modules',
  87. ],
  88. },
  89. resolveLoader: {
  90. modules: ['node_modules'],
  91. },
  92. node: {
  93. // Called by http-link-header in an API we never use, increases
  94. // bundle size unnecessarily
  95. Buffer: false,
  96. },
  97. };