123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. const webpack = require('webpack');
  2. const webpackMerge = require('webpack-merge');
  3. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  4. const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
  5. const Visualizer = require('webpack-visualizer-plugin');
  6. const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
  7. const TerserPlugin = require('terser-webpack-plugin');
  8. const WorkboxPlugin = require('workbox-webpack-plugin');
  9. const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
  10. const path = require('path');
  11. const utils = require('./utils.js');
  12. const commonConfig = require('./webpack.common.js');
  13. const ENV = 'production';
  14. const sass = require('sass');
  15. module.exports = webpackMerge(commonConfig({ env: ENV }), {
  16. // Enable source maps. Please note that this will slow down the build.
  17. // You have to enable it in UglifyJSPlugin config below and in tsconfig-aot.json as well
  18. // devtool: 'source-map',
  19. entry: {
  20. polyfills: './src/main/webapp/app/polyfills',
  21. global: './src/main/webapp/content/scss/global.scss',
  22. main: './src/main/webapp/app/app.main'
  23. },
  24. output: {
  25. path: utils.root('target/classes/public'),
  26. filename: 'app/[name].[hash].bundle.js',
  27. chunkFilename: 'app/[id].[hash].chunk.js'
  28. },
  29. module: {
  30. rules: [{
  31. test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
  32. loader: '@ngtools/webpack'
  33. },
  34. {
  35. test: /\.scss$/,
  36. use: ['to-string-loader', 'css-loader', {
  37. loader: 'sass-loader',
  38. options: { implementation: sass }
  39. }],
  40. exclude: /(vendor\.scss|global\.scss)/
  41. },
  42. {
  43. test: /(vendor\.scss|global\.scss)/,
  44. use: [
  45. MiniCssExtractPlugin.loader,
  46. 'css-loader',
  47. 'postcss-loader',
  48. {
  49. loader: 'sass-loader',
  50. options: { implementation: sass }
  51. }
  52. ]
  53. },
  54. {
  55. test: /\.css$/,
  56. use: ['to-string-loader', 'css-loader'],
  57. exclude: /(vendor\.css|global\.css)/
  58. },
  59. {
  60. test: /(vendor\.css|global\.css)/,
  61. use: [
  62. MiniCssExtractPlugin.loader,
  63. 'css-loader',
  64. 'postcss-loader'
  65. ]
  66. }]
  67. },
  68. optimization: {
  69. runtimeChunk: false,
  70. splitChunks: {
  71. cacheGroups: {
  72. commons: {
  73. test: /[\\/]node_modules[\\/]/,
  74. name: 'vendors',
  75. chunks: 'all'
  76. }
  77. }
  78. },
  79. minimizer: [
  80. new TerserPlugin({
  81. parallel: true,
  82. cache: true,
  83. terserOptions: {
  84. ie8: false,
  85. // sourceMap: true, // Enable source maps. Please note that this will slow down the build
  86. compress: {
  87. dead_code: true,
  88. warnings: false,
  89. properties: true,
  90. drop_debugger: true,
  91. conditionals: true,
  92. booleans: true,
  93. loops: true,
  94. unused: true,
  95. toplevel: true,
  96. if_return: true,
  97. inline: true,
  98. join_vars: true
  99. },
  100. output: {
  101. comments: false,
  102. beautify: false,
  103. indent_level: 2
  104. }
  105. }
  106. }),
  107. new OptimizeCSSAssetsPlugin({})
  108. ]
  109. },
  110. plugins: [
  111. new MiniCssExtractPlugin({
  112. // Options similar to the same options in webpackOptions.output
  113. // both options are optional
  114. filename: '[name].[contenthash].css',
  115. chunkFilename: '[id].css'
  116. }),
  117. new MomentLocalesPlugin({
  118. localesToKeep: [
  119. 'en',
  120. 'es'
  121. // jhipster-needle-i18n-language-moment-webpack - JHipster will add/remove languages in this array
  122. ]
  123. }),
  124. new Visualizer({
  125. // Webpack statistics in target folder
  126. filename: '../stats.html'
  127. }),
  128. new AngularCompilerPlugin({
  129. mainPath: utils.root('src/main/webapp/app/app.main.ts'),
  130. tsConfigPath: utils.root('tsconfig-aot.json'),
  131. sourceMap: true
  132. }),
  133. new webpack.LoaderOptionsPlugin({
  134. minimize: true,
  135. debug: false
  136. }),
  137. new WorkboxPlugin.GenerateSW({
  138. clientsClaim: true,
  139. skipWaiting: true,
  140. })
  141. ],
  142. mode: 'production'
  143. });