webpack.hot.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 CleanWebpackPlugin = require('clean-webpack-plugin');
  9. module.exports = merge(common, {
  10. entry: {
  11. app: ['webpack-dev-server/client?http://localhost:3333', './public/app/dev.ts'],
  12. },
  13. output: {
  14. path: path.resolve(__dirname, '../../public/build'),
  15. filename: '[name].[hash].js',
  16. publicPath: '/public/build/',
  17. pathinfo: false,
  18. },
  19. resolve: {
  20. extensions: ['.scss', '.ts', '.tsx', '.es6', '.js', '.json', '.svg', '.woff2', '.png', '.html'],
  21. },
  22. devtool: 'eval-source-map',
  23. devServer: {
  24. publicPath: '/public/build/',
  25. hot: true,
  26. port: 3333,
  27. proxy: {
  28. '!/public/build': 'http://localhost:3000',
  29. },
  30. },
  31. optimization: {
  32. removeAvailableModules: false,
  33. removeEmptyChunks: false,
  34. splitChunks: false,
  35. },
  36. module: {
  37. rules: [
  38. {
  39. test: /\.tsx?$/,
  40. exclude: /node_modules/,
  41. use: [
  42. {
  43. loader: 'babel-loader',
  44. options: {
  45. cacheDirectory: true,
  46. babelrc: false,
  47. plugins: ['syntax-dynamic-import', 'react-hot-loader/babel'],
  48. },
  49. },
  50. {
  51. loader: 'ts-loader',
  52. options: {
  53. transpileOnly: true,
  54. experimentalWatchApi: true,
  55. },
  56. },
  57. ],
  58. },
  59. {
  60. test: /\.scss$/,
  61. use: [
  62. 'style-loader', // creates style nodes from JS strings
  63. 'css-loader', // translates CSS into CommonJS
  64. {
  65. loader: 'postcss-loader',
  66. options: {
  67. config: { path: __dirname + '/postcss.config.js' },
  68. },
  69. },
  70. 'sass-loader', // compiles Sass to CSS
  71. ],
  72. },
  73. {
  74. test: /\.(png|jpg|gif|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
  75. loader: 'file-loader',
  76. },
  77. ],
  78. },
  79. plugins: [
  80. new CleanWebpackPlugin('../public/build', { allowExternal: true }),
  81. new HtmlWebpackPlugin({
  82. filename: path.resolve(__dirname, '../../public/views/index.html'),
  83. template: path.resolve(__dirname, '../../public/views/index-template.html'),
  84. inject: 'body',
  85. alwaysWriteToDisk: true,
  86. }),
  87. new HtmlWebpackHarddiskPlugin(),
  88. new webpack.NamedModulesPlugin(),
  89. new webpack.HotModuleReplacementPlugin(),
  90. new webpack.DefinePlugin({
  91. GRAFANA_THEME: JSON.stringify(process.env.GRAFANA_THEME || 'dark'),
  92. 'process.env': {
  93. NODE_ENV: JSON.stringify('development'),
  94. },
  95. }),
  96. ],
  97. });