webpack.dev.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 MiniCssExtractPlugin = require("mini-css-extract-plugin");
  9. // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  10. module.exports = merge(common, {
  11. devtool: "cheap-module-source-map",
  12. mode: 'development',
  13. entry: {
  14. app: './public/app/index.ts',
  15. dark: './public/sass/grafana.dark.scss',
  16. light: './public/sass/grafana.light.scss',
  17. },
  18. output: {
  19. path: path.resolve(__dirname, '../../public/build'),
  20. filename: '[name].[hash].js',
  21. // Keep publicPath relative for host.com/grafana/ deployments
  22. publicPath: "public/build/",
  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, minimize: 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('../../public/build', { allowExternal: true }),
  57. new MiniCssExtractPlugin({
  58. filename: "grafana.[name].[hash].css"
  59. }),
  60. new HtmlWebpackPlugin({
  61. filename: path.resolve(__dirname, '../../public/views/error.html'),
  62. template: path.resolve(__dirname, '../../public/views/error-template.html'),
  63. inject: false,
  64. }),
  65. new HtmlWebpackPlugin({
  66. filename: path.resolve(__dirname, '../../public/views/index.html'),
  67. template: path.resolve(__dirname, '../../public/views/index-template.html'),
  68. inject: 'body',
  69. chunks: ['manifest', 'vendor', 'app'],
  70. }),
  71. new webpack.NamedModulesPlugin(),
  72. new webpack.HotModuleReplacementPlugin(),
  73. new webpack.DefinePlugin({
  74. 'process.env': {
  75. 'NODE_ENV': JSON.stringify('development')
  76. }
  77. }),
  78. // new BundleAnalyzerPlugin({
  79. // analyzerPort: 8889
  80. // })
  81. ]
  82. });