webpack.hot.js 3.2 KB

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