From 5cdc7fa83be76d2be83c68d5cee3287a4264225f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 19 May 2025 17:13:08 +0200 Subject: [PATCH] update docs to add swc.config.js support --- .../modern-build-stack/transpiler-swc.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/v3-docs/docs/about/modern-build-stack/transpiler-swc.md b/v3-docs/docs/about/modern-build-stack/transpiler-swc.md index 7b67de62ab..9813a65540 100644 --- a/v3-docs/docs/about/modern-build-stack/transpiler-swc.md +++ b/v3-docs/docs/about/modern-build-stack/transpiler-swc.md @@ -121,6 +121,10 @@ You can also configure other options using the `.swcrc` format. One common case This overrides Meteor's internal SWC config to apply your settings, ensuring SWC processes `.js` or `.ts` files with React components without falling back to Babel. +Use `swc.config.js` in your project root for dynamic configuration. Meteor will import and apply the SWC config automatically. This lets you choose a config based on environment variables or other runtime factors. + +Explore additional custom SWC configs, including ["Import Aliases"](#import-aliases) and ["React Runtime"](#react-runtime). + ## Config API - `modern.transpiler: [true|false]` - Default: `true` @@ -190,6 +194,27 @@ To use the same aliases in SWC, add them to your [.swcrc](#custom-swcrc): } ``` +You can use `swc.config.js` to define different aliases based on an environment variable. + +``` js +var mode = process.env.MODE_ENV; + +var userAliases = { + "@user/*": ["user/*"], +}; + +var adminAliases = { + "@admin/*": ["admin/*"], +}; + +module.exports = { + jsc: { + baseUrl: "./", + paths: mode === "USER" ? uiAliases : adminAliases, + }, +}; +``` + This enables you to use `@ui/components` instead of `./ui/components` in your imports. ### React Runtime