webpack.dev.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. optimization: {
  56. splitChunks: {
  57. cacheGroups: {
  58. manifest: {
  59. chunks: "initial",
  60. test: "vendor",
  61. name: "vendor",
  62. enforce: true
  63. },
  64. vendor: {
  65. chunks: "initial",
  66. test: "vendor",
  67. name: "vendor",
  68. enforce: true
  69. }
  70. }
  71. }
  72. },
  73. plugins: [
  74. new CleanWebpackPlugin('../../public/build', { allowExternal: true }),
  75. new MiniCssExtractPlugin({
  76. filename: "grafana.[name].[hash].css"
  77. }),
  78. new HtmlWebpackPlugin({
  79. filename: path.resolve(__dirname, '../../public/views/error.html'),
  80. template: path.resolve(__dirname, '../../public/views/error.template.html'),
  81. inject: 'false',
  82. }),
  83. new HtmlWebpackPlugin({
  84. filename: path.resolve(__dirname, '../../public/views/index.html'),
  85. template: path.resolve(__dirname, '../../public/views/index.template.html'),
  86. inject: 'body',
  87. chunks: ['manifest', 'vendor', 'app'],
  88. }),
  89. new webpack.NamedModulesPlugin(),
  90. new webpack.HotModuleReplacementPlugin(),
  91. new webpack.DefinePlugin({
  92. 'process.env': {
  93. 'NODE_ENV': JSON.stringify('development')
  94. }
  95. }),
  96. // new BundleAnalyzerPlugin({
  97. // analyzerPort: 8889
  98. // })
  99. ]
  100. });