webpack.hot.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. module.exports = merge(common, {
  11. mode: 'development',
  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. watchOptions: {
  33. ignored: /node_modules/
  34. }
  35. },
  36. optimization: {
  37. removeAvailableModules: false,
  38. removeEmptyChunks: false,
  39. splitChunks: false,
  40. },
  41. module: {
  42. rules: [
  43. {
  44. test: /\.tsx?$/,
  45. exclude: /node_modules/,
  46. use: [
  47. {
  48. loader: 'babel-loader',
  49. options: {
  50. cacheDirectory: true,
  51. babelrc: false,
  52. plugins: [
  53. [require('@rtsao/plugin-proposal-class-properties'), { loose: true }],
  54. 'angularjs-annotate',
  55. '@babel/plugin-syntax-dynamic-import', // needed for `() => import()` in routes.ts
  56. 'react-hot-loader/babel',
  57. ],
  58. presets: [
  59. [
  60. '@babel/preset-env',
  61. {
  62. targets: { browsers: 'last 3 versions' },
  63. useBuiltIns: 'entry',
  64. },
  65. ],
  66. '@babel/preset-typescript',
  67. '@babel/preset-react',
  68. ],
  69. },
  70. },
  71. ],
  72. },
  73. {
  74. test: /\.scss$/,
  75. use: [
  76. 'style-loader', // creates style nodes from JS strings
  77. 'css-loader', // translates CSS into CommonJS
  78. {
  79. loader: 'postcss-loader',
  80. options: {
  81. config: { path: __dirname + '/postcss.config.js' },
  82. },
  83. },
  84. {
  85. loader: 'sass-loader'
  86. }
  87. ],
  88. },
  89. {
  90. test: /\.(png|jpg|gif|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
  91. loader: 'file-loader',
  92. },
  93. ],
  94. },
  95. plugins: [
  96. new CleanWebpackPlugin(),
  97. new HtmlWebpackPlugin({
  98. filename: path.resolve(__dirname, '../../public/views/index.html'),
  99. template: path.resolve(__dirname, '../../public/views/index-template.html'),
  100. inject: 'body',
  101. alwaysWriteToDisk: true,
  102. }),
  103. new HtmlWebpackHarddiskPlugin(),
  104. new webpack.NamedModulesPlugin(),
  105. new webpack.HotModuleReplacementPlugin(),
  106. new webpack.DefinePlugin({
  107. GRAFANA_THEME: JSON.stringify(process.env.GRAFANA_THEME || 'dark'),
  108. 'process.env': {
  109. NODE_ENV: JSON.stringify('development'),
  110. },
  111. }),
  112. new IgnoreNotFoundExportPlugin(),
  113. ],
  114. });