webpack.prod.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. 'use strict';
  2. const merge = require('webpack-merge');
  3. const TerserPlugin = require('terser-webpack-plugin');
  4. const common = require('./webpack.common.js');
  5. const path = require('path');
  6. const ngAnnotatePlugin = require('ng-annotate-webpack-plugin');
  7. const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
  8. const HtmlWebpackPlugin = require("html-webpack-plugin");
  9. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  10. const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
  11. module.exports = merge(common, {
  12. mode: 'production',
  13. devtool: "source-map",
  14. entry: {
  15. dark: './public/sass/grafana.dark.scss',
  16. light: './public/sass/grafana.light.scss',
  17. },
  18. module: {
  19. rules: [{
  20. test: /\.tsx?$/,
  21. enforce: 'pre',
  22. exclude: /node_modules/,
  23. use: {
  24. loader: 'tslint-loader',
  25. options: {
  26. emitErrors: true,
  27. typeCheck: false,
  28. }
  29. }
  30. },
  31. {
  32. test: /\.tsx?$/,
  33. exclude: /node_modules/,
  34. use: {
  35. loader: 'ts-loader',
  36. options: {
  37. transpileOnly: true
  38. },
  39. },
  40. },
  41. require('./sass.rule.js')({
  42. sourceMap: false,
  43. preserveUrl: false
  44. })
  45. ]
  46. },
  47. optimization: {
  48. nodeEnv: 'production',
  49. minimizer: [
  50. new TerserPlugin({
  51. cache: false,
  52. parallel: true,
  53. sourceMap: true
  54. }),
  55. new OptimizeCSSAssetsPlugin({})
  56. ]
  57. },
  58. plugins: [
  59. new ForkTsCheckerWebpackPlugin({
  60. checkSyntacticErrors: true,
  61. }),
  62. new MiniCssExtractPlugin({
  63. filename: "grafana.[name].[hash].css"
  64. }),
  65. new ngAnnotatePlugin(),
  66. new HtmlWebpackPlugin({
  67. filename: path.resolve(__dirname, '../../public/views/error.html'),
  68. template: path.resolve(__dirname, '../../public/views/error-template.html'),
  69. inject: false,
  70. excludeChunks: ['dark', 'light'],
  71. chunksSortMode: 'none'
  72. }),
  73. new HtmlWebpackPlugin({
  74. filename: path.resolve(__dirname, '../../public/views/index.html'),
  75. template: path.resolve(__dirname, '../../public/views/index-template.html'),
  76. inject: 'body',
  77. excludeChunks: ['manifest', 'dark', 'light'],
  78. chunksSortMode: 'none'
  79. }),
  80. function () {
  81. this.hooks.done.tap('Done', function (stats) {
  82. if (stats.compilation.errors && stats.compilation.errors.length) {
  83. console.log(stats.compilation.errors);
  84. process.exit(1);
  85. }
  86. });
  87. }
  88. ]
  89. });