webpack.hot.js 3.4 KB

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