From ab703e3140f66ad97dc34dfac6a07add9e342374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 15 Dec 2025 19:39:18 +0100 Subject: [PATCH] add test coverage CustomConsoleLogPlugin with support for plugin disabling --- .../react/plugins/CustomConsoleLogPlugin.js | 14 ++++++++++++++ .../modern-tests/apps/react/rspack.config.cjs | 8 ++++++++ tools/modern-tests/react.test.js | 15 +++++++++++++++ .../rspack-bundler-integration.md | 19 +++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 tools/modern-tests/apps/react/plugins/CustomConsoleLogPlugin.js diff --git a/tools/modern-tests/apps/react/plugins/CustomConsoleLogPlugin.js b/tools/modern-tests/apps/react/plugins/CustomConsoleLogPlugin.js new file mode 100644 index 0000000000..0e8abd4037 --- /dev/null +++ b/tools/modern-tests/apps/react/plugins/CustomConsoleLogPlugin.js @@ -0,0 +1,14 @@ +// CustomConsoleLogPlugin.js +class CustomConsoleLogPlugin { + apply(compiler) { + compiler.hooks.beforeRun.tap('CustomConsoleLogPlugin', (compilation) => { + console.log('👉 [CustomConsoleLogPlugin] Build is starting...'); + }); + + compiler.hooks.done.tap('CustomConsoleLogPlugin', (stats) => { + console.log('✅ [CustomConsoleLogPlugin] Build finished successfully!'); + }); + } +} + +module.exports = CustomConsoleLogPlugin; diff --git a/tools/modern-tests/apps/react/rspack.config.cjs b/tools/modern-tests/apps/react/rspack.config.cjs index bd2c2e86e8..a28fcc5ac3 100644 --- a/tools/modern-tests/apps/react/rspack.config.cjs +++ b/tools/modern-tests/apps/react/rspack.config.cjs @@ -1,5 +1,6 @@ const { defineConfig } = require('@meteorjs/rspack'); const path = require('path'); +const CustomConsoleLogPlugin = require("./plugins/CustomConsoleLogPlugin"); /** * Rspack configuration for Meteor projects. @@ -12,7 +13,13 @@ const path = require('path'); * Use these flags to adjust your build settings based on environment. */ module.exports = defineConfig(Meteor => { + const disabledPluginMatches = Meteor.isRun + ? ['CustomConsoleLogPlugin'] + : Meteor.isTest + ? /CustomConsoleLogPlugin/i + : p => p?.constructor?.name === 'CustomConsoleLogPlugin'; return { + ...Meteor.disablePlugins(disabledPluginMatches), resolve: { alias: { "@public": path.resolve(__dirname, "public"), @@ -32,5 +39,6 @@ module.exports = defineConfig(Meteor => { }, ], }, + plugins: [new CustomConsoleLogPlugin()], }; }); diff --git a/tools/modern-tests/react.test.js b/tools/modern-tests/react.test.js index 808c18baa5..aec211f128 100644 --- a/tools/modern-tests/react.test.js +++ b/tools/modern-tests/react.test.js @@ -79,6 +79,9 @@ describe('React App Bundling /', () => { // Check if images exist and return 200 status code await assertImagesExistAndLoad(); + + // Check custom plugin is disabled with Meteor.disablePlugins + await waitForMeteorOutput(result.outputLines, /.*CustomConsoleLogPlugin.*/, { negate: true }); }, afterRunRebuildClient: async ({ allConsoleLogs }) => { // Check for HMR output as enabled by default @@ -89,6 +92,9 @@ describe('React App Bundling /', () => { // Check if images exist and return 200 status code await assertImagesExistAndLoad(); + + // Check custom plugin is disabled with Meteor.disablePlugins + await waitForMeteorOutput(result.outputLines, /.*CustomConsoleLogPlugin.*/, { negate: true }); }, afterRunProductionRebuildClient: async ({ allConsoleLogs }) => { // Check for HMR to not be enabled in production-like mode @@ -96,12 +102,21 @@ describe('React App Bundling /', () => { }, afterTest: async ({ result }) => { await waitForReactEnvs(result.outputLines); + + // Check custom plugin is disabled with Meteor.disablePlugins + await waitForMeteorOutput(result.outputLines, /.*CustomConsoleLogPlugin.*/, { negate: true }); }, afterTestOnce: async ({ result }) => { await waitForReactEnvs(result.outputLines); + + // Check custom plugin is disabled with Meteor.disablePlugins + await waitForMeteorOutput(result.outputLines, /.*CustomConsoleLogPlugin.*/, { negate: true }); }, afterBuild: async ({ result }) => { await waitForReactEnvs(result.outputLines, { isJsxEnabled: true }); + + // Check custom plugin is disabled with Meteor.disablePlugins + await waitForMeteorOutput(result.outputLines, /.*CustomConsoleLogPlugin.*/, { negate: true }); }, } })); diff --git a/v3-docs/docs/about/modern-build-stack/rspack-bundler-integration.md b/v3-docs/docs/about/modern-build-stack/rspack-bundler-integration.md index 179371ecd2..4154b514d9 100644 --- a/v3-docs/docs/about/modern-build-stack/rspack-bundler-integration.md +++ b/v3-docs/docs/about/modern-build-stack/rspack-bundler-integration.md @@ -761,6 +761,25 @@ RSPACK_DEVSERVER_PORT=3232 meteor run The reason is that the Rspack dev server is handled by the Meteor so it can make both dev server works together, and the info of the port needs to be properly shared via the env. +### Disable Plugins + +Meteor allows disabling Rspack plugins that are added by default or through presets. This is useful when troubleshooting build issues or replacing a plugin with a custom implementation. + +Plugins are matched by name (constructor name) and can be specified as a string, RegExp, a predicate function, or an array of all. + +``` js +const { defineConfig } = require('@meteorjs/rspack'); + +module.exports = defineConfig(Meteor => ({ + // Disable one or more Rspack plugins + ...Meteor.disablePlugins([ + 'DefinePlugin', + /Html/i, + p => p?.constructor?.name === 'CustomConsoleLogPlugin', + ]), +})); +``` + ## Benefits Meteor–Rspack integration sends your app code to Rspack to use modern bundler features. Meteor then uses Rspack’s output to handle Meteor-specific tasks (like Atmosphere package compilation) and create the final bundle.