webpack.dev.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 CleanWebpackPlugin = require('clean-webpack-plugin');
  8. const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
  9. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  10. // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  11. module.exports = (env = {}) =>
  12. merge(common, {
  13. devtool: 'cheap-module-source-map',
  14. mode: 'development',
  15. entry: {
  16. app: './public/app/index.ts',
  17. dark: './public/sass/grafana.dark.scss',
  18. light: './public/sass/grafana.light.scss',
  19. },
  20. // If we enabled watch option via CLI
  21. watchOptions: {
  22. ignored: /node_modules/,
  23. },
  24. module: {
  25. rules: [{
  26. test: /\.tsx?$/,
  27. enforce: 'pre',
  28. exclude: /node_modules/,
  29. use: {
  30. loader: 'tslint-loader',
  31. options: {
  32. emitErrors: true,
  33. typeCheck: false,
  34. }
  35. }
  36. },
  37. {
  38. test: /\.tsx?$/,
  39. exclude: /node_modules/,
  40. use: {
  41. loader: 'ts-loader',
  42. options: {
  43. transpileOnly: true
  44. },
  45. },
  46. },
  47. require('./sass.rule.js')({
  48. sourceMap: false,
  49. preserveUrl: false
  50. }),
  51. {
  52. test: /\.(png|jpg|gif|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
  53. loader: 'file-loader'
  54. },
  55. ]
  56. },
  57. plugins: [
  58. new CleanWebpackPlugin(),
  59. env.noTsCheck ?
  60. new webpack.DefinePlugin({}) // bogus plugin to satisfy webpack API
  61. :
  62. new ForkTsCheckerWebpackPlugin({
  63. checkSyntacticErrors: true,
  64. }),
  65. new MiniCssExtractPlugin({
  66. filename: 'grafana.[name].[hash].css'
  67. }),
  68. new HtmlWebpackPlugin({
  69. filename: path.resolve(__dirname, '../../public/views/error.html'),
  70. template: path.resolve(__dirname, '../../public/views/error-template.html'),
  71. inject: false,
  72. chunksSortMode: 'none',
  73. excludeChunks: ['dark', 'light']
  74. }),
  75. new HtmlWebpackPlugin({
  76. filename: path.resolve(__dirname, '../../public/views/index.html'),
  77. template: path.resolve(__dirname, '../../public/views/index-template.html'),
  78. inject: 'body',
  79. chunksSortMode: 'none',
  80. excludeChunks: ['dark', 'light']
  81. }),
  82. new webpack.NamedModulesPlugin(),
  83. new webpack.HotModuleReplacementPlugin(),
  84. new webpack.DefinePlugin({
  85. 'process.env': {
  86. NODE_ENV: JSON.stringify('development')
  87. }
  88. }),
  89. // new BundleAnalyzerPlugin({
  90. // analyzerPort: 8889
  91. // })
  92. ]
  93. });