闭社主体 forked from https://github.com/tootsuite/mastodon
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.

113 lines
3.3 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 MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6. const AssetsManifestPlugin = require('webpack-assets-manifest');
  7. const CopyPlugin = require('copy-webpack-plugin');
  8. const extname = require('path-complete-extname');
  9. const { env, settings, themes, output } = require('./configuration');
  10. const rules = require('./rules');
  11. const localePackPaths = require('./generateLocalePacks');
  12. const extensionGlob = `**/*{${settings.extensions.join(',')}}*`;
  13. const entryPath = join(settings.source_path, settings.source_entry_path);
  14. const packPaths = sync(join(entryPath, extensionGlob));
  15. module.exports = {
  16. entry: Object.assign(
  17. packPaths.reduce((map, entry) => {
  18. const localMap = map;
  19. const namespace = relative(join(entryPath), dirname(entry));
  20. localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry);
  21. return localMap;
  22. }, {}),
  23. localePackPaths.reduce((map, entry) => {
  24. const localMap = map;
  25. localMap[basename(entry, extname(entry, extname(entry)))] = resolve(entry);
  26. return localMap;
  27. }, {}),
  28. Object.keys(themes).reduce((themePaths, name) => {
  29. themePaths[name] = resolve(join(settings.source_path, themes[name]));
  30. return themePaths;
  31. }, {}),
  32. ),
  33. output: {
  34. filename: 'js/[name]-[chunkhash].js',
  35. chunkFilename: 'js/[name]-[chunkhash].chunk.js',
  36. hotUpdateChunkFilename: 'js/[id]-[hash].hot-update.js',
  37. path: output.path,
  38. publicPath: output.publicPath,
  39. },
  40. optimization: {
  41. runtimeChunk: {
  42. name: 'common',
  43. },
  44. splitChunks: {
  45. cacheGroups: {
  46. default: false,
  47. vendors: false,
  48. common: {
  49. name: 'common',
  50. chunks: 'all',
  51. minChunks: 2,
  52. minSize: 0,
  53. test: /^(?!.*[\\\/]node_modules[\\\/]react-intl[\\\/]).+$/,
  54. },
  55. },
  56. },
  57. occurrenceOrder: true,
  58. },
  59. module: {
  60. rules: Object.keys(rules).map(key => rules[key]),
  61. },
  62. plugins: [
  63. new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
  64. new webpack.NormalModuleReplacementPlugin(
  65. /^history\//, (resource) => {
  66. // temporary fix for https://github.com/ReactTraining/react-router/issues/5576
  67. // to reduce bundle size
  68. resource.request = resource.request.replace(/^history/, 'history/es');
  69. },
  70. ),
  71. new MiniCssExtractPlugin({
  72. filename: 'css/[name]-[contenthash:8].css',
  73. chunkFilename: 'css/[name]-[contenthash:8].chunk.css',
  74. }),
  75. new AssetsManifestPlugin({
  76. integrity: false,
  77. entrypoints: true,
  78. writeToDisk: true,
  79. publicPath: true,
  80. }),
  81. new CopyPlugin({
  82. patterns: [
  83. { from: 'node_modules/tesseract.js/dist/worker.min.js', to: 'ocr' },
  84. { from: 'node_modules/tesseract.js-core/tesseract-core.wasm.js', to: 'ocr' },
  85. ],
  86. }),
  87. ],
  88. resolve: {
  89. extensions: settings.extensions,
  90. modules: [
  91. resolve(settings.source_path),
  92. 'node_modules',
  93. ],
  94. },
  95. resolveLoader: {
  96. modules: ['node_modules'],
  97. },
  98. node: {
  99. // Called by http-link-header in an API we never use, increases
  100. // bundle size unnecessarily
  101. Buffer: false,
  102. },
  103. };