The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

128 lines
3.7 KiB

  1. // Note: You must restart bin/webpack-dev-server for changes to take effect
  2. const merge = require('webpack-merge');
  3. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  4. const CompressionPlugin = require('compression-webpack-plugin');
  5. const sharedConfig = require('./shared.js');
  6. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  7. const OfflinePlugin = require('offline-plugin');
  8. const { publicPath } = require('./configuration.js');
  9. const path = require('path');
  10. const { URL } = require('url');
  11. let compressionAlgorithm;
  12. try {
  13. const zopfli = require('node-zopfli');
  14. compressionAlgorithm = (content, options, fn) => {
  15. zopfli.gzip(content, options, fn);
  16. };
  17. } catch (error) {
  18. compressionAlgorithm = 'gzip';
  19. }
  20. let attachmentHost;
  21. if (process.env.S3_ENABLED === 'true') {
  22. if (process.env.S3_ALIAS_HOST || process.env.S3_CLOUDFRONT_HOST) {
  23. attachmentHost = process.env.S3_ALIAS_HOST || process.env.S3_CLOUDFRONT_HOST;
  24. } else {
  25. attachmentHost = process.env.S3_HOSTNAME || `s3-${process.env.S3_REGION || 'us-east-1'}.amazonaws.com`;
  26. }
  27. } else if (process.env.SWIFT_ENABLED === 'true') {
  28. const { host } = new URL(process.env.SWIFT_OBJECT_URL);
  29. attachmentHost = host;
  30. } else {
  31. attachmentHost = null;
  32. }
  33. module.exports = merge(sharedConfig, {
  34. mode: 'production',
  35. output: {
  36. filename: '[name]-[chunkhash].js',
  37. chunkFilename: '[name]-[chunkhash].js',
  38. },
  39. devtool: 'source-map', // separate sourcemap file, suitable for production
  40. stats: 'normal',
  41. optimization: {
  42. minimize: true,
  43. minimizer: [
  44. new UglifyJsPlugin({
  45. sourceMap: true,
  46. uglifyOptions: {
  47. mangle: true,
  48. compress: {
  49. warnings: false,
  50. },
  51. output: {
  52. comments: false,
  53. },
  54. },
  55. }),
  56. ],
  57. },
  58. plugins: [
  59. new CompressionPlugin({
  60. algorithm: compressionAlgorithm,
  61. test: /\.(js|css|html|json|ico|svg|eot|otf|ttf)$/,
  62. }),
  63. new BundleAnalyzerPlugin({ // generates report.html and stats.json
  64. analyzerMode: 'static',
  65. generateStatsFile: true,
  66. statsOptions: {
  67. // allows usage with http://chrisbateman.github.io/webpack-visualizer/
  68. chunkModules: true,
  69. },
  70. openAnalyzer: false,
  71. logLevel: 'silent', // do not bother Webpacker, who runs with --json and parses stdout
  72. }),
  73. new OfflinePlugin({
  74. publicPath: publicPath, // sw.js must be served from the root to avoid scope issues
  75. caches: {
  76. main: [':rest:'],
  77. additional: [':externals:'],
  78. optional: [
  79. '**/locale_*.js', // don't fetch every locale; the user only needs one
  80. '**/*_polyfills-*.js', // the user may not need polyfills
  81. '**/*.woff2', // the user may have system-fonts enabled
  82. // images/audio can be cached on-demand
  83. '**/*.png',
  84. '**/*.jpg',
  85. '**/*.jpeg',
  86. '**/*.svg',
  87. '**/*.mp3',
  88. '**/*.ogg',
  89. ],
  90. },
  91. externals: [
  92. '/emoji/1f602.svg', // used for emoji picker dropdown
  93. '/emoji/sheet_10.png', // used in emoji-mart
  94. ],
  95. excludes: [
  96. '**/*.gz',
  97. '**/*.map',
  98. 'stats.json',
  99. 'report.html',
  100. // any browser that supports ServiceWorker will support woff2
  101. '**/*.eot',
  102. '**/*.ttf',
  103. '**/*-webfont-*.svg',
  104. '**/*.woff',
  105. ],
  106. ServiceWorker: {
  107. entry: `imports-loader?ATTACHMENT_HOST=>${encodeURIComponent(JSON.stringify(attachmentHost))}!${encodeURI(path.join(__dirname, '../../app/javascript/mastodon/service_worker/entry.js'))}`,
  108. cacheName: 'mastodon',
  109. output: '../assets/sw.js',
  110. publicPath: '/sw.js',
  111. minify: true,
  112. },
  113. }),
  114. ],
  115. });