webpack.dev.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. {
  27. test: /\.tsx?$/,
  28. enforce: 'pre',
  29. exclude: /node_modules/,
  30. use: {
  31. loader: 'tslint-loader',
  32. options: {
  33. emitErrors: true,
  34. typeCheck: false,
  35. },
  36. },
  37. },
  38. {
  39. test: /\.tsx?$/,
  40. exclude: /node_modules/,
  41. use: {
  42. loader: 'ts-loader',
  43. options: {
  44. transpileOnly: true,
  45. },
  46. },
  47. },
  48. require('./sass.rule.js')({ sourceMap: false, preserveUrl: false }),
  49. {
  50. test: /\.(png|jpg|gif|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
  51. loader: 'file-loader',
  52. },
  53. ],
  54. },
  55. plugins: [
  56. new CleanWebpackPlugin(),
  57. env.noTsCheck
  58. ? new webpack.DefinePlugin({}) // bogus plugin to satisfy webpack API
  59. : new ForkTsCheckerWebpackPlugin({
  60. checkSyntacticErrors: true,
  61. }),
  62. new MiniCssExtractPlugin({
  63. filename: 'grafana.[name].[hash].css',
  64. }),
  65. new HtmlWebpackPlugin({
  66. filename: path.resolve(__dirname, '../../public/views/error.html'),
  67. template: path.resolve(__dirname, '../../public/views/error-template.html'),
  68. inject: false,
  69. }),
  70. new HtmlWebpackPlugin({
  71. filename: path.resolve(__dirname, '../../public/views/index.html'),
  72. template: path.resolve(__dirname, '../../public/views/index-template.html'),
  73. inject: 'body',
  74. chunks: ['manifest', 'vendor', 'app'],
  75. }),
  76. new webpack.NamedModulesPlugin(),
  77. new webpack.HotModuleReplacementPlugin(),
  78. new webpack.DefinePlugin({
  79. 'process.env': {
  80. NODE_ENV: JSON.stringify('development'),
  81. },
  82. }),
  83. // new BundleAnalyzerPlugin({
  84. // analyzerPort: 8889
  85. // })
  86. ],
  87. });