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.

91 lines
2.8 KiB

  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 ExtractTextPlugin = require('extract-text-webpack-plugin');
  6. const ManifestPlugin = require('webpack-manifest-plugin');
  7. const extname = require('path-complete-extname');
  8. const { env, settings, themes, output, loadersDir } = require('./configuration.js');
  9. const localePackPaths = require('./generateLocalePacks');
  10. const extensionGlob = `**/*{${settings.extensions.join(',')}}*`;
  11. const entryPath = join(settings.source_path, settings.source_entry_path);
  12. const packPaths = sync(join(entryPath, extensionGlob));
  13. const entryPacks = [...packPaths, ...localePackPaths].filter(path => path !== join(entryPath, 'custom.js'));
  14. const themePaths = Object.keys(themes).reduce(
  15. (themePaths, name) => {
  16. const themeData = themes[name];
  17. themePaths[`themes/${name}`] = resolve(themeData.pack_directory, themeData.pack);
  18. return themePaths;
  19. }, {}
  20. );
  21. module.exports = {
  22. entry: Object.assign(
  23. entryPacks.reduce(
  24. (map, entry) => {
  25. const localMap = map;
  26. let namespace = relative(join(entryPath), dirname(entry));
  27. if (namespace === join('..', '..', '..', 'tmp', 'packs')) {
  28. namespace = ''; // generated by generateLocalePacks.js
  29. }
  30. localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry);
  31. return localMap;
  32. }, {}
  33. ), themePaths
  34. ),
  35. output: {
  36. filename: '[name].js',
  37. chunkFilename: '[name].js',
  38. path: output.path,
  39. publicPath: output.publicPath,
  40. },
  41. module: {
  42. rules: sync(join(loadersDir, '*.js')).map(loader => require(loader)),
  43. },
  44. plugins: [
  45. new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
  46. new webpack.NormalModuleReplacementPlugin(
  47. /^history\//, (resource) => {
  48. // temporary fix for https://github.com/ReactTraining/react-router/issues/5576
  49. // to reduce bundle size
  50. resource.request = resource.request.replace(/^history/, 'history/es');
  51. }
  52. ),
  53. new ExtractTextPlugin({
  54. filename: env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css',
  55. allChunks: true,
  56. }),
  57. new ManifestPlugin({
  58. publicPath: output.publicPath,
  59. writeToFileEmit: true,
  60. }),
  61. new webpack.optimize.CommonsChunkPlugin({
  62. name: 'common',
  63. minChunks: Infinity, // It doesn't make sense to use common chunks with multiple frontend support.
  64. }),
  65. ],
  66. resolve: {
  67. extensions: settings.extensions,
  68. modules: [
  69. resolve(settings.source_path),
  70. 'node_modules',
  71. ],
  72. },
  73. resolveLoader: {
  74. modules: ['node_modules'],
  75. },
  76. node: {
  77. // Called by http-link-header in an API we never use, increases
  78. // bundle size unnecessarily
  79. Buffer: false,
  80. },
  81. };