a small private-blog service

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