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.

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