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.
 
 
 
 
 

136 lines
4.2 KiB

  1. 'use strict'
  2. const fs = require('fs')
  3. const path = require('path')
  4. const utils = require('./utils')
  5. const webpack = require('webpack')
  6. const config = require('../config')
  7. const merge = require('webpack-merge')
  8. const baseWebpackConfig = require('./webpack.base.conf')
  9. const CopyWebpackPlugin = require('copy-webpack-plugin')
  10. const HtmlWebpackPlugin = require('html-webpack-plugin')
  11. const ExtractTextPlugin = require('extract-text-webpack-plugin')
  12. const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
  13. const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
  14. const loadMinified = require('./load-minified')
  15. const env = config.build.env
  16. const webpackConfig = merge(baseWebpackConfig, {
  17. module: {
  18. rules: utils.styleLoaders({
  19. sourceMap: config.build.productionSourceMap,
  20. extract: true
  21. })
  22. },
  23. devtool: config.build.productionSourceMap ? '#source-map' : false,
  24. output: {
  25. path: config.build.assetsRoot,
  26. filename: utils.assetsPath('js/[name].[chunkhash].js'),
  27. chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
  28. },
  29. plugins: [
  30. // http://vuejs.github.io/vue-loader/en/workflow/production.html
  31. new webpack.DefinePlugin({
  32. 'process.env': env
  33. }),
  34. new webpack.optimize.UglifyJsPlugin({
  35. compress: {
  36. warnings: false
  37. },
  38. sourceMap: true
  39. }),
  40. // extract css into its own file
  41. new ExtractTextPlugin({
  42. filename: utils.assetsPath('css/[name].[contenthash].css')
  43. }),
  44. // Compress extracted CSS. We are using this plugin so that possible
  45. // duplicated CSS from different components can be deduped.
  46. new OptimizeCSSPlugin({
  47. cssProcessorOptions: {
  48. safe: true
  49. }
  50. }),
  51. // generate dist index.html with correct asset hash for caching.
  52. // you can customize output by editing /index.html
  53. // see https://github.com/ampedandwired/html-webpack-plugin
  54. new HtmlWebpackPlugin({
  55. filename: config.build.index,
  56. template: 'index.html',
  57. inject: true,
  58. minify: {
  59. removeComments: true,
  60. collapseWhitespace: true,
  61. removeAttributeQuotes: true
  62. // more options:
  63. // https://github.com/kangax/html-minifier#options-quick-reference
  64. },
  65. // necessary to consistently work with multiple chunks via CommonsChunkPlugin
  66. chunksSortMode: 'dependency',
  67. serviceWorkerLoader: `<script>${loadMinified(path.join(__dirname,
  68. './service-worker-prod.js'))}</script>`
  69. }),
  70. // split vendor js into its own file
  71. new webpack.optimize.CommonsChunkPlugin({
  72. name: 'vendor',
  73. minChunks: function (module, count) {
  74. // any required modules inside node_modules are extracted to vendor
  75. return (
  76. module.resource &&
  77. /\.js$/.test(module.resource) &&
  78. module.resource.indexOf(
  79. path.join(__dirname, '../node_modules')
  80. ) === 0
  81. )
  82. }
  83. }),
  84. // extract webpack runtime and module manifest to its own file in order to
  85. // prevent vendor hash from being updated whenever app bundle is updated
  86. new webpack.optimize.CommonsChunkPlugin({
  87. name: 'manifest',
  88. chunks: ['vendor']
  89. }),
  90. // copy custom static assets
  91. new CopyWebpackPlugin([
  92. {
  93. from: path.resolve(__dirname, '../static'),
  94. to: config.build.assetsSubDirectory,
  95. ignore: ['.*']
  96. }
  97. ]),
  98. // service worker caching
  99. new SWPrecacheWebpackPlugin({
  100. cacheId: 'nexus-timers',
  101. filename: 'service-worker.js',
  102. staticFileGlobs: ['dist/**/*.{js,html,css}'],
  103. minify: true,
  104. stripPrefix: 'dist/'
  105. })
  106. ]
  107. })
  108. if (config.build.productionGzip) {
  109. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  110. webpackConfig.plugins.push(
  111. new CompressionWebpackPlugin({
  112. asset: '[path].gz[query]',
  113. algorithm: 'gzip',
  114. test: new RegExp(
  115. '\\.(' +
  116. config.build.productionGzipExtensions.join('|') +
  117. ')$'
  118. ),
  119. threshold: 10240,
  120. minRatio: 0.8
  121. })
  122. )
  123. }
  124. if (config.build.bundleAnalyzerReport) {
  125. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  126. webpackConfig.plugins.push(new BundleAnalyzerPlugin())
  127. }
  128. module.exports = webpackConfig