webpack.prod.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. 'use strict';
  2. const merge = require('webpack-merge');
  3. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  4. const common = require('./webpack.common.js');
  5. const path = require('path');
  6. const ngAnnotatePlugin = require('ng-annotate-webpack-plugin');
  7. const HtmlWebpackPlugin = require("html-webpack-plugin");
  8. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  9. const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
  10. module.exports = merge(common, {
  11. mode: 'production',
  12. devtool: "source-map",
  13. entry: {
  14. dark: './public/sass/grafana.dark.scss',
  15. light: './public/sass/grafana.light.scss',
  16. },
  17. module: {
  18. rules: [
  19. {
  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, minimize: false, preserveUrl: false
  43. })
  44. ]
  45. },
  46. optimization: {
  47. splitChunks: {
  48. cacheGroups: {
  49. commons: {
  50. test: /[\\/]node_modules[\\/].*[jt]sx?$/,
  51. name: "vendor",
  52. chunks: "all"
  53. }
  54. }
  55. },
  56. minimizer: [
  57. new UglifyJsPlugin({
  58. cache: true,
  59. parallel: true,
  60. sourceMap: true
  61. }),
  62. new OptimizeCSSAssetsPlugin({})
  63. ]
  64. },
  65. plugins: [
  66. new MiniCssExtractPlugin({
  67. filename: "grafana.[name].[hash].css"
  68. }),
  69. new ngAnnotatePlugin(),
  70. new HtmlWebpackPlugin({
  71. filename: path.resolve(__dirname, '../../public/views/error.html'),
  72. template: path.resolve(__dirname, '../../public/views/error-template.html'),
  73. inject: false,
  74. }),
  75. new HtmlWebpackPlugin({
  76. filename: path.resolve(__dirname, '../../public/views/index.html'),
  77. template: path.resolve(__dirname, '../../public/views/index-template.html'),
  78. inject: 'body',
  79. chunks: ['vendor', 'app'],
  80. }),
  81. function () {
  82. this.hooks.done.tap('Done', function (stats) {
  83. if (stats.compilation.errors && stats.compilation.errors.length) {
  84. console.log(stats.compilation.errors);
  85. process.exit(1);
  86. }
  87. });
  88. }
  89. ]
  90. });