logo

pleroma-fe

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

webpack.prod.conf.js (3213B)


  1. var path = require('path')
  2. var config = require('../config')
  3. var utils = require('./utils')
  4. var webpack = require('webpack')
  5. var merge = require('webpack-merge')
  6. var baseWebpackConfig = require('./webpack.base.conf')
  7. var MiniCssExtractPlugin = require('mini-css-extract-plugin')
  8. const CssMinimizerPlugin = require("css-minimizer-webpack-plugin")
  9. var HtmlWebpackPlugin = require('html-webpack-plugin')
  10. var env = process.env.NODE_ENV === 'testing'
  11. ? require('../config/test.env')
  12. : config.build.env
  13. let commitHash = (() => {
  14. const subst = "$Format:%h$";
  15. if(!subst.match(/Format:/)) {
  16. return subst;
  17. } else {
  18. return require('child_process')
  19. .execSync('git rev-parse --short HEAD')
  20. .toString();
  21. }
  22. })();
  23. var webpackConfig = merge(baseWebpackConfig, {
  24. mode: 'production',
  25. module: {
  26. rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, extract: true })
  27. },
  28. devtool: config.build.productionSourceMap ? 'source-map' : false,
  29. optimization: {
  30. minimize: true,
  31. splitChunks: {
  32. chunks: 'all'
  33. },
  34. minimizer: [
  35. `...`,
  36. new CssMinimizerPlugin()
  37. ]
  38. },
  39. output: {
  40. path: config.build.assetsRoot,
  41. filename: utils.assetsPath('js/[name].[chunkhash].js'),
  42. chunkFilename: utils.assetsPath('js/[name].[chunkhash].js')
  43. },
  44. plugins: [
  45. // http://vuejs.github.io/vue-loader/workflow/production.html
  46. new webpack.DefinePlugin({
  47. 'process.env': env,
  48. 'COMMIT_HASH': JSON.stringify(commitHash),
  49. 'DEV_OVERRIDES': JSON.stringify(undefined),
  50. '__VUE_OPTIONS_API__': true,
  51. '__VUE_PROD_DEVTOOLS__': false,
  52. '__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': false
  53. }),
  54. // extract css into its own file
  55. new MiniCssExtractPlugin({
  56. filename: utils.assetsPath('css/[name].[contenthash].css')
  57. }),
  58. // generate dist index.html with correct asset hash for caching.
  59. // you can customize output by editing /index.html
  60. // see https://github.com/ampedandwired/html-webpack-plugin
  61. new HtmlWebpackPlugin({
  62. filename: process.env.NODE_ENV === 'testing'
  63. ? 'index.html'
  64. : config.build.index,
  65. template: 'index.html',
  66. inject: true,
  67. minify: {
  68. removeComments: true,
  69. collapseWhitespace: true,
  70. removeAttributeQuotes: true,
  71. ignoreCustomComments: [/server-generated-meta/]
  72. // more options:
  73. // https://github.com/kangax/html-minifier#options-quick-reference
  74. }
  75. }),
  76. // split vendor js into its own file
  77. // extract webpack runtime and module manifest to its own file in order to
  78. // prevent vendor hash from being updated whenever app bundle is updated
  79. // new webpack.optimize.SplitChunksPlugin({
  80. // name: ['app', 'vendor']
  81. // }),
  82. ]
  83. })
  84. if (config.build.productionGzip) {
  85. var CompressionWebpackPlugin = require('compression-webpack-plugin')
  86. webpackConfig.plugins.push(
  87. new CompressionWebpackPlugin({
  88. asset: '[path].gz[query]',
  89. algorithm: 'gzip',
  90. test: new RegExp(
  91. '\\.(' +
  92. config.build.productionGzipExtensions.join('|') +
  93. ')$'
  94. ),
  95. threshold: 10240,
  96. minRatio: 0.8
  97. })
  98. )
  99. }
  100. module.exports = webpackConfig