闭社主体 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.

86 lines
2.9 KiB

  1. // Note: You must restart bin/webpack-dev-server for changes to take effect
  2. const { existsSync } = require('fs');
  3. const webpack = require('webpack');
  4. const { basename, dirname, join, relative, resolve, sep } = require('path');
  5. const { sync } = require('glob');
  6. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  7. const ManifestPlugin = require('webpack-manifest-plugin');
  8. const extname = require('path-complete-extname');
  9. const { env, paths, publicPath, loadersDir } = require('./configuration.js');
  10. const localePackPaths = require('./generateLocalePacks');
  11. const extensionGlob = `**/*{${paths.extensions.join(',')}}*`;
  12. const packPaths = sync(join(paths.source, paths.entry, extensionGlob));
  13. const entryPacks = [].concat(packPaths).concat(localePackPaths);
  14. const customApplicationStyle = resolve(join(paths.source, 'styles/custom.scss'));
  15. const originalApplicationStyle = resolve(join(paths.source, 'styles/application.scss'));
  16. module.exports = {
  17. entry: entryPacks.reduce(
  18. (map, entry) => {
  19. const localMap = map;
  20. let namespace = relative(join(paths.source, paths.entry), dirname(entry));
  21. if (namespace === join('..', '..', '..', 'tmp', 'packs')) {
  22. namespace = ''; // generated by generateLocalePacks.js
  23. }
  24. localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry);
  25. return localMap;
  26. }, {}
  27. ),
  28. output: {
  29. filename: '[name].js',
  30. chunkFilename: '[name]-[chunkhash].js',
  31. path: resolve(paths.output, paths.entry),
  32. publicPath,
  33. },
  34. module: {
  35. rules: sync(join(loadersDir, '*.js')).map(loader => require(loader)),
  36. },
  37. plugins: [
  38. new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
  39. new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'),
  40. new ManifestPlugin({ fileName: paths.manifest, publicPath, writeToFileEmit: true }),
  41. new webpack.optimize.CommonsChunkPlugin({
  42. name: 'common',
  43. minChunks: (module, count) => {
  44. const reactIntlPathRegexp = new RegExp(`node_modules\\${sep}react-intl`);
  45. if (module.resource && reactIntlPathRegexp.test(module.resource)) {
  46. // skip react-intl because it's useless to put in the common chunk,
  47. // e.g. because "shared" modules between zh-TW and zh-CN will never
  48. // be loaded together
  49. return false;
  50. }
  51. return count >= 2;
  52. },
  53. }),
  54. ],
  55. resolve: {
  56. alias: {
  57. 'mastodon-application-style': existsSync(customApplicationStyle) ?
  58. customApplicationStyle : originalApplicationStyle,
  59. },
  60. extensions: paths.extensions,
  61. modules: [
  62. resolve(paths.source),
  63. resolve(paths.node_modules),
  64. ],
  65. },
  66. resolveLoader: {
  67. modules: [paths.node_modules],
  68. },
  69. node: {
  70. // Called by http-link-header in an API we never use, increases
  71. // bundle size unnecessarily
  72. Buffer: false,
  73. },
  74. };