webpack.hot.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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: [
  48. [require('@rtsao/plugin-proposal-class-properties'), { loose: true }],
  49. 'angularjs-annotate',
  50. 'syntax-dynamic-import', // needed for `() => import()` in routes.ts
  51. 'react-hot-loader/babel',
  52. ],
  53. presets: [
  54. [
  55. '@babel/preset-env',
  56. {
  57. targets: { browsers: 'last 3 versions' },
  58. useBuiltIns: 'entry',
  59. },
  60. ],
  61. '@babel/preset-typescript',
  62. '@babel/preset-react',
  63. ],
  64. },
  65. },
  66. ],
  67. },
  68. {
  69. test: /\.scss$/,
  70. use: [
  71. 'style-loader', // creates style nodes from JS strings
  72. 'css-loader', // translates CSS into CommonJS
  73. {
  74. loader: 'postcss-loader',
  75. options: {
  76. config: { path: __dirname + '/postcss.config.js' },
  77. },
  78. },
  79. 'sass-loader', // compiles Sass to CSS
  80. ],
  81. },
  82. {
  83. test: /\.(png|jpg|gif|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
  84. loader: 'file-loader',
  85. },
  86. ],
  87. },
  88. plugins: [
  89. new CleanWebpackPlugin('../public/build', { allowExternal: true }),
  90. new HtmlWebpackPlugin({
  91. filename: path.resolve(__dirname, '../../public/views/index.html'),
  92. template: path.resolve(__dirname, '../../public/views/index-template.html'),
  93. inject: 'body',
  94. alwaysWriteToDisk: true,
  95. }),
  96. new HtmlWebpackHarddiskPlugin(),
  97. new webpack.NamedModulesPlugin(),
  98. new webpack.HotModuleReplacementPlugin(),
  99. new webpack.DefinePlugin({
  100. GRAFANA_THEME: JSON.stringify(process.env.GRAFANA_THEME || 'dark'),
  101. 'process.env': {
  102. NODE_ENV: JSON.stringify('development'),
  103. },
  104. }),
  105. ],
  106. });