webpack.prod.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 ExtractTextPlugin = require("extract-text-webpack-plugin");
  10. const pkg = require('../../package.json');
  11. let dependencies = Object.keys(pkg.dependencies);
  12. module.exports = merge(common, {
  13. devtool: "source-map",
  14. entry: {
  15. dark: './public/sass/grafana.dark.scss',
  16. light: './public/sass/grafana.light.scss',
  17. vendor: dependencies,
  18. },
  19. module: {
  20. rules: [
  21. require('./sass.rule.js')({
  22. sourceMap: false, minimize: true
  23. })
  24. ]
  25. },
  26. plugins: [
  27. new ExtractTextPlugin({
  28. filename: 'grafana.[name].css',
  29. }),
  30. new ngAnnotatePlugin(),
  31. new UglifyJSPlugin({
  32. sourceMap: true,
  33. }),
  34. new webpack.DefinePlugin({
  35. 'process.env': {
  36. 'NODE_ENV': JSON.stringify('production')
  37. }
  38. }),
  39. new HtmlWebpackPlugin({
  40. filename: path.resolve(__dirname, '../../public/views/index.html'),
  41. template: path.resolve(__dirname, '../../public/views/index.template.html'),
  42. inject: 'body',
  43. chunks: ['manifest', 'vendor', 'app'],
  44. }),
  45. new webpack.optimize.CommonsChunkPlugin({
  46. names: ['vendor', 'manifest'],
  47. }),
  48. function() {
  49. this.plugin("done", function(stats) {
  50. if (stats.compilation.errors && stats.compilation.errors.length) {
  51. console.log(stats.compilation.errors);
  52. process.exit(1);
  53. }
  54. });
  55. }
  56. ]
  57. });