webpack.prod.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. {
  21. test: /\.tsx?$/,
  22. enforce: 'pre',
  23. exclude: /node_modules/,
  24. use: {
  25. loader: 'tslint-loader',
  26. options: {
  27. emitErrors: true,
  28. typeCheck: false,
  29. }
  30. }
  31. },
  32. {
  33. test: /\.tsx?$/,
  34. exclude: /node_modules/,
  35. use: {
  36. loader: 'ts-loader',
  37. options: {
  38. transpileOnly: true
  39. },
  40. },
  41. },
  42. require('./sass.rule.js')({
  43. sourceMap: false, preserveUrl: false
  44. })
  45. ]
  46. },
  47. optimization: {
  48. minimizer: [
  49. new TerserPlugin({
  50. cache: false,
  51. parallel: true,
  52. sourceMap: true
  53. }),
  54. new OptimizeCSSAssetsPlugin({})
  55. ]
  56. },
  57. plugins: [
  58. new ForkTsCheckerWebpackPlugin({
  59. checkSyntacticErrors: true,
  60. }),
  61. new MiniCssExtractPlugin({
  62. filename: "grafana.[name].[hash].css"
  63. }),
  64. new ngAnnotatePlugin(),
  65. new HtmlWebpackPlugin({
  66. filename: path.resolve(__dirname, '../../public/views/error.html'),
  67. template: path.resolve(__dirname, '../../public/views/error-template.html'),
  68. inject: false,
  69. }),
  70. new HtmlWebpackPlugin({
  71. filename: path.resolve(__dirname, '../../public/views/index.html'),
  72. template: path.resolve(__dirname, '../../public/views/index-template.html'),
  73. inject: 'body',
  74. chunks: ['vendor', 'app'],
  75. }),
  76. function () {
  77. this.hooks.done.tap('Done', function (stats) {
  78. if (stats.compilation.errors && stats.compilation.errors.length) {
  79. console.log(stats.compilation.errors);
  80. process.exit(1);
  81. }
  82. });
  83. }
  84. ]
  85. });