webpack.hot.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. const IgnoreNotFoundExportPlugin = require("./IgnoreNotFoundExportPlugin.js");
  10. const getThemeVariable = require("./getThemeVariable");
  11. module.exports = merge(common, {
  12. entry: {
  13. app: ['webpack-dev-server/client?http://localhost:3333', './public/app/dev.ts'],
  14. },
  15. output: {
  16. path: path.resolve(__dirname, '../../public/build'),
  17. filename: '[name].[hash].js',
  18. publicPath: '/public/build/',
  19. pathinfo: false,
  20. },
  21. resolve: {
  22. extensions: ['.scss', '.ts', '.tsx', '.es6', '.js', '.json', '.svg', '.woff2', '.png', '.html'],
  23. },
  24. devtool: 'eval-source-map',
  25. devServer: {
  26. publicPath: '/public/build/',
  27. hot: true,
  28. port: 3333,
  29. proxy: {
  30. '!/public/build': 'http://localhost:3000',
  31. },
  32. },
  33. optimization: {
  34. removeAvailableModules: false,
  35. removeEmptyChunks: false,
  36. splitChunks: false,
  37. },
  38. module: {
  39. rules: [
  40. {
  41. test: /\.tsx?$/,
  42. exclude: /node_modules/,
  43. use: [
  44. {
  45. loader: 'babel-loader',
  46. options: {
  47. cacheDirectory: true,
  48. babelrc: false,
  49. plugins: [
  50. [require('@rtsao/plugin-proposal-class-properties'), { loose: true }],
  51. 'angularjs-annotate',
  52. 'syntax-dynamic-import', // needed for `() => import()` in routes.ts
  53. 'react-hot-loader/babel',
  54. ],
  55. presets: [
  56. [
  57. '@babel/preset-env',
  58. {
  59. targets: { browsers: 'last 3 versions' },
  60. useBuiltIns: 'entry',
  61. },
  62. ],
  63. '@babel/preset-typescript',
  64. '@babel/preset-react',
  65. ],
  66. },
  67. },
  68. ],
  69. },
  70. {
  71. test: /\.scss$/,
  72. use: [
  73. 'style-loader', // creates style nodes from JS strings
  74. 'css-loader', // translates CSS into CommonJS
  75. {
  76. loader: 'postcss-loader',
  77. options: {
  78. config: { path: __dirname + '/postcss.config.js' },
  79. },
  80. },
  81. {
  82. loader: 'sass-loader',
  83. options: {
  84. functions: {
  85. "getThemeVariable($themeVar, $themeName: dark)": getThemeVariable
  86. }
  87. }
  88. }
  89. ],
  90. },
  91. {
  92. test: /\.(png|jpg|gif|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
  93. loader: 'file-loader',
  94. },
  95. ],
  96. },
  97. plugins: [
  98. new CleanWebpackPlugin('../public/build', { allowExternal: true }),
  99. new HtmlWebpackPlugin({
  100. filename: path.resolve(__dirname, '../../public/views/index.html'),
  101. template: path.resolve(__dirname, '../../public/views/index-template.html'),
  102. inject: 'body',
  103. alwaysWriteToDisk: true,
  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 IgnoreNotFoundExportPlugin(),
  115. ],
  116. });