Timers and other features for Heroes of the Storm
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.
 
 
 
 
 

155 line
4.9 KiB

  1. /*
  2. * Copyright © 2021 Adrien Agez <adrien.agez@pm.me>
  3. *
  4. * This file is part of Nexus Timers.
  5. *
  6. * Nexus Timers is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Nexus Timers is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with Nexus Timers. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. 'use strict'
  20. const fs = require('fs')
  21. const path = require('path')
  22. const utils = require('./utils')
  23. const webpack = require('webpack')
  24. const config = require('../config')
  25. const merge = require('webpack-merge')
  26. const baseWebpackConfig = require('./webpack.base.conf')
  27. const CopyWebpackPlugin = require('copy-webpack-plugin')
  28. const HtmlWebpackPlugin = require('html-webpack-plugin')
  29. const ExtractTextPlugin = require('extract-text-webpack-plugin')
  30. const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
  31. const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
  32. const loadMinified = require('./load-minified')
  33. const env = config.build.env
  34. const webpackConfig = merge(baseWebpackConfig, {
  35. module: {
  36. rules: utils.styleLoaders({
  37. sourceMap: config.build.productionSourceMap,
  38. extract: true
  39. })
  40. },
  41. devtool: config.build.productionSourceMap ? '#source-map' : false,
  42. output: {
  43. path: config.build.assetsRoot,
  44. filename: utils.assetsPath('js/[name].[chunkhash].js'),
  45. chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
  46. },
  47. plugins: [
  48. // http://vuejs.github.io/vue-loader/en/workflow/production.html
  49. new webpack.DefinePlugin({
  50. 'process.env': env
  51. }),
  52. new webpack.optimize.UglifyJsPlugin({
  53. compress: {
  54. warnings: false
  55. },
  56. sourceMap: true
  57. }),
  58. // extract css into its own file
  59. new ExtractTextPlugin({
  60. filename: utils.assetsPath('css/[name].[contenthash].css')
  61. }),
  62. // Compress extracted CSS. We are using this plugin so that possible
  63. // duplicated CSS from different components can be deduped.
  64. new OptimizeCSSPlugin({
  65. cssProcessorOptions: {
  66. safe: true
  67. }
  68. }),
  69. // generate dist index.html with correct asset hash for caching.
  70. // you can customize output by editing /index.html
  71. // see https://github.com/ampedandwired/html-webpack-plugin
  72. new HtmlWebpackPlugin({
  73. filename: config.build.index,
  74. template: 'index.html',
  75. inject: true,
  76. minify: {
  77. removeComments: true,
  78. collapseWhitespace: true,
  79. removeAttributeQuotes: true
  80. // more options:
  81. // https://github.com/kangax/html-minifier#options-quick-reference
  82. },
  83. // necessary to consistently work with multiple chunks via CommonsChunkPlugin
  84. chunksSortMode: 'dependency',
  85. serviceWorkerLoader: `<script>${loadMinified(path.join(__dirname,
  86. './service-worker-prod.js'))}</script>`
  87. }),
  88. // split vendor js into its own file
  89. new webpack.optimize.CommonsChunkPlugin({
  90. name: 'vendor',
  91. minChunks: function (module, count) {
  92. // any required modules inside node_modules are extracted to vendor
  93. return (
  94. module.resource &&
  95. /\.js$/.test(module.resource) &&
  96. module.resource.indexOf(
  97. path.join(__dirname, '../node_modules')
  98. ) === 0
  99. )
  100. }
  101. }),
  102. // extract webpack runtime and module manifest to its own file in order to
  103. // prevent vendor hash from being updated whenever app bundle is updated
  104. new webpack.optimize.CommonsChunkPlugin({
  105. name: 'manifest',
  106. chunks: ['vendor']
  107. }),
  108. // copy custom static assets
  109. new CopyWebpackPlugin([
  110. {
  111. from: path.resolve(__dirname, '../static'),
  112. to: config.build.assetsSubDirectory,
  113. ignore: ['.*']
  114. }
  115. ]),
  116. // service worker caching
  117. new SWPrecacheWebpackPlugin({
  118. cacheId: 'nexus-timers',
  119. filename: 'service-worker.js',
  120. staticFileGlobs: ['dist/**/*.{js,html,css}'],
  121. minify: true,
  122. stripPrefix: 'dist/'
  123. })
  124. ]
  125. })
  126. if (config.build.productionGzip) {
  127. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  128. webpackConfig.plugins.push(
  129. new CompressionWebpackPlugin({
  130. asset: '[path].gz[query]',
  131. algorithm: 'gzip',
  132. test: new RegExp(
  133. '\\.(' +
  134. config.build.productionGzipExtensions.join('|') +
  135. ')$'
  136. ),
  137. threshold: 10240,
  138. minRatio: 0.8
  139. })
  140. )
  141. }
  142. if (config.build.bundleAnalyzerReport) {
  143. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  144. webpackConfig.plugins.push(new BundleAnalyzerPlugin())
  145. }
  146. module.exports = webpackConfig