logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

shared.js (3011B)


  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, sep } = 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((themePaths, name) => {
  27. themePaths[name] = resolve(join(settings.source_path, themes[name]));
  28. return themePaths;
  29. }, {})
  30. ),
  31. output: {
  32. filename: '[name].js',
  33. chunkFilename: '[name].js',
  34. path: output.path,
  35. publicPath: output.publicPath,
  36. },
  37. module: {
  38. rules: sync(join(loadersDir, '*.js')).map(loader => require(loader)),
  39. },
  40. plugins: [
  41. new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
  42. new webpack.NormalModuleReplacementPlugin(
  43. /^history\//, (resource) => {
  44. // temporary fix for https://github.com/ReactTraining/react-router/issues/5576
  45. // to reduce bundle size
  46. resource.request = resource.request.replace(/^history/, 'history/es');
  47. }
  48. ),
  49. new ExtractTextPlugin('[name].css'),
  50. new ManifestPlugin({
  51. publicPath: output.publicPath,
  52. writeToFileEmit: true,
  53. }),
  54. new webpack.optimize.CommonsChunkPlugin({
  55. name: 'common',
  56. minChunks: (module, count) => {
  57. const reactIntlPathRegexp = new RegExp(`node_modules\\${sep}react-intl`);
  58. if (module.resource && reactIntlPathRegexp.test(module.resource)) {
  59. // skip react-intl because it's useless to put in the common chunk,
  60. // e.g. because "shared" modules between zh-TW and zh-CN will never
  61. // be loaded together
  62. return false;
  63. }
  64. return count >= 2;
  65. },
  66. }),
  67. ],
  68. resolve: {
  69. extensions: settings.extensions,
  70. modules: [
  71. resolve(settings.source_path),
  72. 'node_modules',
  73. ],
  74. },
  75. resolveLoader: {
  76. modules: ['node_modules'],
  77. },
  78. node: {
  79. // Called by http-link-header in an API we never use, increases
  80. // bundle size unnecessarily
  81. Buffer: false,
  82. },
  83. };