webpack.prod.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. minimizer: [
  48. new UglifyJsPlugin({
  49. cache: true,
  50. parallel: true,
  51. sourceMap: true
  52. }),
  53. new OptimizeCSSAssetsPlugin({})
  54. ]
  55. },
  56. plugins: [
  57. new MiniCssExtractPlugin({
  58. filename: "grafana.[name].[hash].css"
  59. }),
  60. new ngAnnotatePlugin(),
  61. new HtmlWebpackPlugin({
  62. filename: path.resolve(__dirname, '../../public/views/error.html'),
  63. template: path.resolve(__dirname, '../../public/views/error-template.html'),
  64. inject: false,
  65. }),
  66. new HtmlWebpackPlugin({
  67. filename: path.resolve(__dirname, '../../public/views/index.html'),
  68. template: path.resolve(__dirname, '../../public/views/index-template.html'),
  69. inject: 'body',
  70. chunks: ['vendor', 'app'],
  71. }),
  72. function () {
  73. this.hooks.done.tap('Done', function (stats) {
  74. if (stats.compilation.errors && stats.compilation.errors.length) {
  75. console.log(stats.compilation.errors);
  76. process.exit(1);
  77. }
  78. });
  79. }
  80. ]
  81. });