2025-05-12 05:34:17 -04:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
2017-10-01 14:02:25 -04:00
|
|
|
const path = require('path');
|
2021-09-02 08:18:07 -04:00
|
|
|
const webpack = require('webpack');
|
2022-04-22 09:33:13 -04:00
|
|
|
|
2021-11-09 12:05:01 -05:00
|
|
|
const CorsWorkerPlugin = require('./plugins/CorsWorkerPlugin');
|
2020-06-29 13:58:47 -04:00
|
|
|
|
2026-02-20 09:41:43 -05:00
|
|
|
module.exports = (env = {}) => ({
|
2017-10-01 14:02:25 -04:00
|
|
|
target: 'web',
|
|
|
|
|
entry: {
|
|
|
|
|
app: './public/app/index.ts',
|
2025-04-25 17:07:43 -04:00
|
|
|
swagger: './public/swagger/index.tsx',
|
2017-10-01 14:02:25 -04:00
|
|
|
},
|
2024-11-05 02:34:09 -05:00
|
|
|
experiments: {
|
|
|
|
|
// Required to load WASM modules.
|
|
|
|
|
asyncWebAssembly: true,
|
|
|
|
|
},
|
2017-10-01 14:02:25 -04:00
|
|
|
output: {
|
2026-02-20 09:41:43 -05:00
|
|
|
clean: env.react19 ? false : true,
|
2017-10-01 14:02:25 -04:00
|
|
|
path: path.resolve(__dirname, '../../public/build'),
|
2026-02-20 09:41:43 -05:00
|
|
|
filename: env.react19 ? '[name]-react19.[contenthash].js' : '[name].[contenthash].js',
|
2026-03-30 01:12:02 -04:00
|
|
|
chunkFilename: env.react19 ? '[name]-react19.[contenthash].js' : '[name].[contenthash].js',
|
2019-03-05 07:29:54 -05:00
|
|
|
publicPath: 'public/build/',
|
2017-10-01 14:02:25 -04:00
|
|
|
},
|
|
|
|
|
resolve: {
|
2025-12-18 05:47:38 -05:00
|
|
|
conditionNames: ['@grafana-app/source', '...'],
|
2018-10-09 13:46:31 -04:00
|
|
|
extensions: ['.ts', '.tsx', '.es6', '.js', '.json', '.svg'],
|
2020-01-30 04:54:11 -05:00
|
|
|
alias: {
|
2022-05-26 05:49:18 -04:00
|
|
|
// some of data source plugins use global Prism object to add the language definition
|
2020-12-02 08:09:55 -05:00
|
|
|
// we want to have same Prism object in core and in grafana/ui
|
2021-10-27 09:21:07 -04:00
|
|
|
prismjs: require.resolve('prismjs'),
|
2023-06-21 08:49:22 -04:00
|
|
|
// due to our webpack configuration not understanding package.json `exports`
|
|
|
|
|
// correctly we must alias this package to the correct file
|
|
|
|
|
// the alternative to this alias is to copy-paste the file into our
|
|
|
|
|
// source code and miss out in updates
|
|
|
|
|
'@locker/near-membrane-dom/custom-devtools-formatter': require.resolve(
|
|
|
|
|
'@locker/near-membrane-dom/custom-devtools-formatter.js'
|
|
|
|
|
),
|
2020-01-30 04:54:11 -05:00
|
|
|
},
|
2024-01-30 10:59:18 -05:00
|
|
|
modules: [
|
|
|
|
|
// default value
|
|
|
|
|
'node_modules',
|
|
|
|
|
|
|
|
|
|
// required for grafana enterprise resolution
|
|
|
|
|
path.resolve('node_modules'),
|
|
|
|
|
|
|
|
|
|
// required to for 'bare' imports (like 'app/core/utils' etc)
|
|
|
|
|
path.resolve('public'),
|
|
|
|
|
],
|
2021-08-31 06:55:05 -04:00
|
|
|
fallback: {
|
2021-10-08 10:19:10 -04:00
|
|
|
buffer: false,
|
2021-08-31 06:55:05 -04:00
|
|
|
fs: false,
|
|
|
|
|
stream: false,
|
2021-09-10 12:05:03 -04:00
|
|
|
http: false,
|
|
|
|
|
https: false,
|
2021-10-27 09:21:07 -04:00
|
|
|
string_decoder: false,
|
2021-08-31 06:55:05 -04:00
|
|
|
},
|
2017-10-01 14:02:25 -04:00
|
|
|
},
|
2024-02-22 06:31:40 -05:00
|
|
|
ignoreWarnings: [
|
|
|
|
|
/export .* was not found in/,
|
|
|
|
|
{
|
|
|
|
|
module: /@kusto\/language-service\/bridge\.min\.js$/,
|
|
|
|
|
message: /^Critical dependency: the request of a dependency is an expression$/,
|
|
|
|
|
},
|
|
|
|
|
],
|
2020-06-29 13:58:47 -04:00
|
|
|
plugins: [
|
2026-02-20 09:41:43 -05:00
|
|
|
...(env.react19
|
|
|
|
|
? [
|
|
|
|
|
new webpack.NormalModuleReplacementPlugin(/^react$/, (resource) => {
|
|
|
|
|
resource.request = resource.request.replace('react', 'react-19');
|
|
|
|
|
}),
|
|
|
|
|
new webpack.NormalModuleReplacementPlugin(/^react-dom/, (resource) => {
|
|
|
|
|
resource.request = resource.request.replace('react-dom', 'react-dom-19');
|
|
|
|
|
}),
|
|
|
|
|
new webpack.NormalModuleReplacementPlugin(/^react\/jsx-runtime$/, (resource) => {
|
|
|
|
|
resource.request = resource.request.replace('react/jsx-runtime', 'react-19/jsx-runtime');
|
|
|
|
|
}),
|
|
|
|
|
new webpack.NormalModuleReplacementPlugin(/^react\/jsx-dev-runtime/, (resource) => {
|
|
|
|
|
resource.request = resource.request.replace('react/jsx-dev-runtime', 'react-19/jsx-dev-runtime');
|
|
|
|
|
}),
|
|
|
|
|
]
|
|
|
|
|
: []),
|
2021-11-09 12:05:01 -05:00
|
|
|
new CorsWorkerPlugin(),
|
2021-09-02 08:18:07 -04:00
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
|
Buffer: ['buffer', 'Buffer'],
|
|
|
|
|
}),
|
2025-05-12 05:34:17 -04:00
|
|
|
new CopyWebpackPlugin({
|
|
|
|
|
patterns: [
|
|
|
|
|
{
|
|
|
|
|
from: 'public/img',
|
|
|
|
|
to: 'img',
|
|
|
|
|
},
|
2025-08-29 11:29:57 -04:00
|
|
|
{
|
|
|
|
|
from: 'public/maps',
|
|
|
|
|
to: 'maps',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: 'public/gazetteer',
|
|
|
|
|
to: 'gazetteer',
|
|
|
|
|
},
|
2025-05-12 05:34:17 -04:00
|
|
|
],
|
|
|
|
|
}),
|
2020-06-29 13:58:47 -04:00
|
|
|
],
|
2017-10-01 14:02:25 -04:00
|
|
|
module: {
|
2020-01-23 02:33:39 -05:00
|
|
|
rules: [
|
|
|
|
|
{
|
2017-10-01 14:02:25 -04:00
|
|
|
test: require.resolve('jquery'),
|
2021-08-31 06:55:05 -04:00
|
|
|
loader: 'expose-loader',
|
|
|
|
|
options: {
|
|
|
|
|
exposes: ['$', 'jQuery'],
|
|
|
|
|
},
|
2017-10-01 14:02:25 -04:00
|
|
|
},
|
2021-04-01 10:09:56 -04:00
|
|
|
{
|
2022-08-04 04:29:42 -04:00
|
|
|
test: /\.(svg|ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,
|
|
|
|
|
type: 'asset/resource',
|
|
|
|
|
generator: { filename: 'static/img/[name].[hash:8][ext]' },
|
2021-04-01 10:09:56 -04:00
|
|
|
},
|
2024-05-28 11:04:03 -04:00
|
|
|
{
|
|
|
|
|
// Required for msagl library (used in Nodegraph panel) to work
|
|
|
|
|
test: /\.m?js$/,
|
|
|
|
|
resolve: {
|
|
|
|
|
fullySpecified: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-09-03 04:29:02 -04:00
|
|
|
],
|
2017-10-01 14:02:25 -04:00
|
|
|
},
|
2019-03-05 07:29:54 -05:00
|
|
|
// https://webpack.js.org/plugins/split-chunks-plugin/#split-chunks-example-3
|
|
|
|
|
optimization: {
|
2019-09-03 04:29:02 -04:00
|
|
|
runtimeChunk: 'single',
|
2019-03-05 07:29:54 -05:00
|
|
|
splitChunks: {
|
2019-09-03 04:29:02 -04:00
|
|
|
chunks: 'all',
|
|
|
|
|
minChunks: 1,
|
2019-03-05 07:29:54 -05:00
|
|
|
cacheGroups: {
|
2019-09-03 04:29:02 -04:00
|
|
|
moment: {
|
|
|
|
|
test: /[\\/]node_modules[\\/]moment[\\/].*[jt]sx?$/,
|
|
|
|
|
chunks: 'initial',
|
|
|
|
|
priority: 20,
|
2020-01-23 02:33:39 -05:00
|
|
|
enforce: true,
|
2019-09-03 04:29:02 -04:00
|
|
|
},
|
|
|
|
|
angular: {
|
|
|
|
|
test: /[\\/]node_modules[\\/]angular[\\/].*[jt]sx?$/,
|
|
|
|
|
chunks: 'initial',
|
|
|
|
|
priority: 50,
|
2020-01-23 02:33:39 -05:00
|
|
|
enforce: true,
|
2019-09-03 04:29:02 -04:00
|
|
|
},
|
2021-08-31 06:55:05 -04:00
|
|
|
defaultVendors: {
|
2019-03-05 07:29:54 -05:00
|
|
|
test: /[\\/]node_modules[\\/].*[jt]sx?$/,
|
2019-09-03 04:29:02 -04:00
|
|
|
chunks: 'initial',
|
|
|
|
|
priority: -10,
|
|
|
|
|
reuseExistingChunk: true,
|
2020-01-23 02:33:39 -05:00
|
|
|
enforce: true,
|
2019-09-03 04:29:02 -04:00
|
|
|
},
|
|
|
|
|
default: {
|
|
|
|
|
priority: -20,
|
|
|
|
|
chunks: 'all',
|
|
|
|
|
test: /.*[jt]sx?$/,
|
2020-01-23 02:33:39 -05:00
|
|
|
reuseExistingChunk: true,
|
2019-09-03 04:29:02 -04:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-02-20 09:41:43 -05:00
|
|
|
});
|