diff --git a/scripts/webpack/empty.js b/scripts/webpack/empty.js new file mode 100644 index 00000000000..c6c83d26ad6 --- /dev/null +++ b/scripts/webpack/empty.js @@ -0,0 +1,2 @@ +// Empty module used by webpack to replace test libraries in production builds +module.exports = {}; diff --git a/scripts/webpack/webpack.prod.js b/scripts/webpack/webpack.prod.js index 4a23f28b60d..96a9376dc04 100644 --- a/scripts/webpack/webpack.prod.js +++ b/scripts/webpack/webpack.prod.js @@ -6,7 +6,7 @@ const { EsbuildPlugin } = require('esbuild-loader'); const { resolveToEsbuildTarget } = require('esbuild-plugin-browserslist'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const path = require('path'); -const { EnvironmentPlugin } = require('webpack'); +const { EnvironmentPlugin, NormalModuleReplacementPlugin } = require('webpack'); const WebpackAssetsManifest = require('webpack-assets-manifest'); const { WebpackManifestPlugin } = require('webpack-manifest-plugin'); const { merge } = require('webpack-merge'); @@ -75,6 +75,11 @@ module.exports = (env = {}) => }, plugins: [ + // Replace any imports of test libraries with empty modules to prevent them from being bundled + // TODO figure out where these are being included, stop that from happening and remove this + new NormalModuleReplacementPlugin(/@testing-library/, (resource) => { + resource.request = require.resolve('./empty.js'); + }), new MiniCssExtractPlugin({ filename: 'grafana.[name].[contenthash].css', }),