webpack.prod.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 webpack = require('webpack');
  6. const path = require('path');
  7. const ngAnnotatePlugin = require('ng-annotate-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, minimize: false, preserveUrl: false
  44. })
  45. ]
  46. },
  47. optimization: {
  48. splitChunks: {
  49. cacheGroups: {
  50. commons: {
  51. test: /[\\/]node_modules[\\/].*[jt]sx?$/,
  52. name: "vendor",
  53. chunks: "all"
  54. }
  55. }
  56. },
  57. minimizer: [
  58. new UglifyJsPlugin({
  59. cache: true,
  60. parallel: true,
  61. sourceMap: true
  62. }),
  63. new OptimizeCSSAssetsPlugin({})
  64. ]
  65. },
  66. plugins: [
  67. new MiniCssExtractPlugin({
  68. filename: "grafana.[name].css"
  69. }),
  70. new ngAnnotatePlugin(),
  71. new HtmlWebpackPlugin({
  72. filename: path.resolve(__dirname, '../../public/views/index.html'),
  73. template: path.resolve(__dirname, '../../public/views/index.template.html'),
  74. inject: 'body',
  75. chunks: ['vendor', 'app'],
  76. }),
  77. function () {
  78. this.hooks.done.tap('Done', function (stats) {
  79. if (stats.compilation.errors && stats.compilation.errors.length) {
  80. console.log(stats.compilation.errors);
  81. process.exit(1);
  82. }
  83. });
  84. }
  85. ]
  86. });