| 
									
										
										
										
											2017-10-02 02:02:25 +08:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-23 19:15:05 +08:00
										 |  |  | const browserslist = require('browserslist'); | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); | 
					
						
							| 
									
										
										
										
											2023-06-01 16:23:09 +08:00
										 |  |  | const { EsbuildPlugin } = require('esbuild-loader'); | 
					
						
							| 
									
										
										
										
											2023-01-23 19:15:05 +08:00
										 |  |  | const { resolveToEsbuildTarget } = require('esbuild-plugin-browserslist'); | 
					
						
							| 
									
										
										
										
											2020-01-30 17:54:11 +08:00
										 |  |  | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2024-08-13 20:07:42 +08:00
										 |  |  | const { EnvironmentPlugin } = require('webpack'); | 
					
						
							| 
									
										
										
										
											2023-12-05 15:34:22 +08:00
										 |  |  | const WebpackAssetsManifest = require('webpack-assets-manifest'); | 
					
						
							| 
									
										
										
										
											2022-08-30 17:18:55 +08:00
										 |  |  | const { WebpackManifestPlugin } = require('webpack-manifest-plugin'); | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | const { merge } = require('webpack-merge'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-13 20:07:42 +08:00
										 |  |  | const getEnvConfig = require('./env-util.js'); | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | const common = require('./webpack.common.js'); | 
					
						
							| 
									
										
										
										
											2023-01-23 19:15:05 +08:00
										 |  |  | const esbuildTargets = resolveToEsbuildTarget(browserslist(), { printUnknownTargets: false }); | 
					
						
							| 
									
										
										
										
											2017-10-02 02:02:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-01 16:23:09 +08:00
										 |  |  | // esbuild-loader 3.0.0+ requires format to be set to prevent it
 | 
					
						
							|  |  |  | // from defaulting to 'iife' which breaks monaco/loader once minified.
 | 
					
						
							|  |  |  | const esbuildOptions = { | 
					
						
							|  |  |  |   target: esbuildTargets, | 
					
						
							|  |  |  |   format: undefined, | 
					
						
							| 
									
										
										
										
											2024-06-25 19:43:47 +08:00
										 |  |  |   jsx: 'automatic', | 
					
						
							| 
									
										
										
										
											2023-06-01 16:23:09 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-13 20:07:42 +08:00
										 |  |  | const envConfig = getEnvConfig(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-11 21:32:34 +08:00
										 |  |  | module.exports = (env = {}) => | 
					
						
							|  |  |  |   merge(common, { | 
					
						
							|  |  |  |     mode: 'production', | 
					
						
							|  |  |  |     devtool: 'source-map', | 
					
						
							| 
									
										
										
										
											2017-10-02 02:02:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-11 21:32:34 +08:00
										 |  |  |     entry: { | 
					
						
							|  |  |  |       dark: './public/sass/grafana.dark.scss', | 
					
						
							|  |  |  |       light: './public/sass/grafana.light.scss', | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2017-10-02 02:02:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-11 21:32:34 +08:00
										 |  |  |     module: { | 
					
						
							|  |  |  |       // Note: order is bottom-to-top and/or right-to-left
 | 
					
						
							|  |  |  |       rules: [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           test: /\.tsx?$/, | 
					
						
							| 
									
										
										
										
											2023-01-23 19:15:05 +08:00
										 |  |  |           use: { | 
					
						
							|  |  |  |             loader: 'esbuild-loader', | 
					
						
							| 
									
										
										
										
											2023-06-01 16:23:09 +08:00
										 |  |  |             options: esbuildOptions, | 
					
						
							| 
									
										
										
										
											2023-01-23 19:15:05 +08:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2021-11-11 21:32:34 +08:00
										 |  |  |         }, | 
					
						
							|  |  |  |         require('./sass.rule.js')({ | 
					
						
							|  |  |  |           sourceMap: false, | 
					
						
							| 
									
										
										
										
											2024-10-25 19:45:44 +08:00
										 |  |  |           preserveUrl: true, | 
					
						
							| 
									
										
										
										
											2021-11-11 21:32:34 +08:00
										 |  |  |         }), | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     optimization: { | 
					
						
							|  |  |  |       nodeEnv: 'production', | 
					
						
							|  |  |  |       minimize: parseInt(env.noMinify, 10) !== 1, | 
					
						
							| 
									
										
										
										
											2023-06-01 16:23:09 +08:00
										 |  |  |       minimizer: [new EsbuildPlugin(esbuildOptions), new CssMinimizerPlugin()], | 
					
						
							| 
									
										
										
										
											2021-11-11 21:32:34 +08:00
										 |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // enable persistent cache for faster builds
 | 
					
						
							|  |  |  |     cache: { | 
					
						
							|  |  |  |       type: 'filesystem', | 
					
						
							|  |  |  |       name: 'grafana-default-production', | 
					
						
							|  |  |  |       buildDependencies: { | 
					
						
							|  |  |  |         config: [__filename], | 
					
						
							| 
									
										
										
										
											2018-04-18 21:01:36 +08:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-11-11 21:32:34 +08:00
										 |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     plugins: [ | 
					
						
							|  |  |  |       new MiniCssExtractPlugin({ | 
					
						
							| 
									
										
										
										
											2022-05-26 17:49:18 +08:00
										 |  |  |         filename: 'grafana.[name].[contenthash].css', | 
					
						
							| 
									
										
										
										
											2020-01-30 17:54:11 +08:00
										 |  |  |       }), | 
					
						
							| 
									
										
										
										
											2023-12-05 15:34:22 +08:00
										 |  |  |       /** | 
					
						
							|  |  |  |        * I know we have two manifest plugins here. | 
					
						
							|  |  |  |        * WebpackManifestPlugin was only used in prod before and does not support integrity hashes | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       new WebpackAssetsManifest({ | 
					
						
							|  |  |  |         entrypoints: true, | 
					
						
							|  |  |  |         integrity: true, | 
					
						
							|  |  |  |         publicPath: true, | 
					
						
							| 
									
										
										
										
											2021-11-11 21:32:34 +08:00
										 |  |  |       }), | 
					
						
							| 
									
										
										
										
											2022-08-30 17:18:55 +08:00
										 |  |  |       new WebpackManifestPlugin({ | 
					
						
							|  |  |  |         fileName: path.join(process.cwd(), 'manifest.json'), | 
					
						
							|  |  |  |         filter: (file) => !file.name.endsWith('.map'), | 
					
						
							|  |  |  |       }), | 
					
						
							| 
									
										
										
										
											2021-11-11 21:32:34 +08:00
										 |  |  |       function () { | 
					
						
							|  |  |  |         this.hooks.done.tap('Done', function (stats) { | 
					
						
							|  |  |  |           if (stats.compilation.errors && stats.compilation.errors.length) { | 
					
						
							|  |  |  |             console.log(stats.compilation.errors); | 
					
						
							|  |  |  |             process.exit(1); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2024-08-13 20:07:42 +08:00
										 |  |  |       new EnvironmentPlugin(envConfig), | 
					
						
							| 
									
										
										
										
											2020-01-30 17:54:11 +08:00
										 |  |  |     ], | 
					
						
							| 
									
										
										
										
											2021-11-11 21:32:34 +08:00
										 |  |  |   }); |