webpack.dev.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
  8. const ExtractTextPlugin = require("extract-text-webpack-plugin");
  9. const CleanWebpackPlugin = require('clean-webpack-plugin');
  10. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  11. const TARGET = process.env.npm_lifecycle_event;
  12. const HOT = TARGET === 'start';
  13. const extractSass = new ExtractTextPlugin({
  14. filename: "grafana.[name].css",
  15. disable: HOT
  16. });
  17. const entries = HOT ? {
  18. app: [
  19. 'webpack-dev-server/client?http://localhost:3333',
  20. './public/app/dev.ts',
  21. ],
  22. vendor: require('./dependencies'),
  23. } : {
  24. app: './public/app/index.ts',
  25. dark: './public/sass/grafana.dark.scss',
  26. light: './public/sass/grafana.light.scss',
  27. vendor: require('./dependencies'),
  28. };
  29. module.exports = merge(common, {
  30. devtool: "cheap-module-source-map",
  31. entry: entries,
  32. resolve: {
  33. extensions: ['.scss', '.ts', '.tsx', '.es6', '.js', '.json', '.svg', '.woff2', '.png'],
  34. },
  35. devServer: {
  36. publicPath: '/public/build/',
  37. hot: HOT,
  38. port: 3333,
  39. proxy: {
  40. '!/public/build': 'http://localhost:3000'
  41. }
  42. },
  43. module: {
  44. rules: [
  45. {
  46. test: /\.tsx?$/,
  47. enforce: 'pre',
  48. exclude: /node_modules/,
  49. use: {
  50. loader: 'tslint-loader',
  51. options: {
  52. emitErrors: true,
  53. typeCheck: false,
  54. }
  55. }
  56. },
  57. {
  58. test: /\.tsx?$/,
  59. exclude: /node_modules/,
  60. use: [
  61. {
  62. loader: 'babel-loader',
  63. options: {
  64. plugins: [
  65. 'react-hot-loader/babel',
  66. ],
  67. },
  68. },
  69. {
  70. loader: 'awesome-typescript-loader',
  71. options: {
  72. useCache: true,
  73. },
  74. }
  75. ]
  76. },
  77. require('./sass.rule.js')({
  78. sourceMap: true, minimize: false, preserveUrl: true
  79. }, extractSass),
  80. {
  81. test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
  82. loader: 'file-loader'
  83. },
  84. {
  85. test: /\.(png|jpg|gif)$/,
  86. use: [
  87. {
  88. loader: 'file-loader',
  89. options: {}
  90. }
  91. ]
  92. },
  93. ]
  94. },
  95. plugins: [
  96. new CleanWebpackPlugin('../public/build', { allowExternal: true }),
  97. extractSass,
  98. new HtmlWebpackPlugin({
  99. filename: path.resolve(__dirname, '../../public/views/index.html'),
  100. template: path.resolve(__dirname, '../../public/views/index.template.html'),
  101. inject: 'body',
  102. chunks: ['manifest', 'vendor', 'app'],
  103. alwaysWriteToDisk: HOT
  104. }),
  105. new HtmlWebpackHarddiskPlugin(),
  106. new webpack.NamedModulesPlugin(),
  107. new webpack.HotModuleReplacementPlugin(),
  108. new webpack.DefinePlugin({
  109. 'GRAFANA_THEME': JSON.stringify(process.env.GRAFANA_THEME || 'dark'),
  110. 'process.env': {
  111. 'NODE_ENV': JSON.stringify('development')
  112. }
  113. }),
  114. new webpack.optimize.CommonsChunkPlugin({
  115. names: ['vendor', 'manifest'],
  116. }),
  117. // new BundleAnalyzerPlugin({
  118. // analyzerPort: 8889
  119. // })
  120. ]
  121. });