webpack.dev.js 2.6 KB

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