webpack.dev.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 'use strict';
  2. const merge = require('webpack-merge');
  3. const common = require('./webpack.common.js');
  4. const path = require('path');
  5. const webpack = require('webpack');
  6. const HtmlWebpackPlugin = require("html-webpack-plugin");
  7. const ExtractTextPlugin = require("extract-text-webpack-plugin");
  8. const CleanWebpackPlugin = require('clean-webpack-plugin');
  9. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  10. const extractSass = new ExtractTextPlugin({
  11. filename: "grafana.[name].css"
  12. });
  13. module.exports = merge(common, {
  14. devtool: "cheap-module-source-map",
  15. entry: {
  16. app: './public/app/index.ts',
  17. dark: './public/sass/grafana.dark.scss',
  18. light: './public/sass/grafana.light.scss',
  19. vendor: require('./dependencies'),
  20. },
  21. output: {
  22. path: path.resolve(__dirname, '../../public/build'),
  23. filename: '[name].[hash].js',
  24. // Keep publicPath relative for host.com/grafana/ deployments
  25. publicPath: "public/build/",
  26. },
  27. module: {
  28. rules: [
  29. {
  30. test: /\.tsx?$/,
  31. enforce: 'pre',
  32. exclude: /node_modules/,
  33. use: {
  34. loader: 'tslint-loader',
  35. options: {
  36. emitErrors: true,
  37. typeCheck: false,
  38. }
  39. }
  40. },
  41. {
  42. test: /\.tsx?$/,
  43. exclude: /node_modules/,
  44. use: {
  45. loader: 'awesome-typescript-loader',
  46. options: {
  47. useCache: true,
  48. },
  49. }
  50. },
  51. require('./sass.rule.js')({
  52. sourceMap: true, minimize: false, preserveUrl: false
  53. }, extractSass),
  54. {
  55. test: /\.(png|jpg|gif|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
  56. loader: 'file-loader'
  57. },
  58. ]
  59. },
  60. plugins: [
  61. new CleanWebpackPlugin('../../public/build', { allowExternal: true }),
  62. extractSass,
  63. new HtmlWebpackPlugin({
  64. filename: path.resolve(__dirname, '../../public/views/index.html'),
  65. template: path.resolve(__dirname, '../../public/views/index.template.html'),
  66. inject: 'body',
  67. chunks: ['manifest', 'vendor', 'app'],
  68. }),
  69. new webpack.NamedModulesPlugin(),
  70. new webpack.HotModuleReplacementPlugin(),
  71. new webpack.DefinePlugin({
  72. 'process.env': {
  73. 'NODE_ENV': JSON.stringify('development')
  74. }
  75. }),
  76. new webpack.optimize.CommonsChunkPlugin({
  77. names: ['vendor', 'manifest'],
  78. }),
  79. // new BundleAnalyzerPlugin({
  80. // analyzerPort: 8889
  81. // })
  82. ]
  83. });