migrate-to-rspack
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMigrate an existing app to Rspack
将现有应用迁移至Rspack
Rspack compiles app code while Meteor builds Atmosphere packages and assembles
the final bundle. Do not rewrite packages merely because Rspack is enabled, but
audit their architecture declarations and browser-incompatible dependencies.
Prerequisite: Meteor 3.4+. Strongly recommended to enable
first (Meteor 3.3+) and fix Babel fallbacks,
then add Rspack. See the skill for the
activation knobs and shape.
"meteor": { "modern": true }meteor-modern-build-stackrspack.config.jsMatch to the Meteor release, not to
or :
@meteorjs/rspack@rspack/core@rspack/cli| Meteor | | | Capability boundary |
|---|---|---|---|
| 3.4 | | | Base integration and helpers. |
| 3.4.1 and 3.5 | | | Adds v2 helpers and inherited |
| 3.5.1 | | | Revised client polyfills and extension discovery. |
The Atmosphere, Meteor npm integration, and Rspack core package versions are
independent. Inspect , , and the lockfile. After
changing the Meteor release, run , inspect the npm changes,
and commit the dependency files. Do not pair a newer integration major with an
older Meteor release only to copy a current helper.
.meteor/versionspackage.jsonmeteor update --npmRspack负责编译应用代码,而Meteor负责构建Atmosphere包并组装最终bundle。不要仅仅因为启用了Rspack就重写包,而是要检查它们的架构声明和浏览器不兼容的依赖项。
前提条件:Meteor 3.4及以上版本。强烈建议先启用(Meteor 3.3及以上版本可用)并修复Babel回退问题,再添加Rspack。有关激活选项和的结构,请查看技能。
"meteor": { "modern": true }rspack.config.jsmeteor-modern-build-stack请将版本与Meteor版本匹配,而非与或版本匹配:
@meteorjs/rspack@rspack/core@rspack/cli| Meteor版本 | | | 功能边界 |
|---|---|---|---|
| 3.4 | | | 基础集成与辅助工具。 |
| 3.4.1 和 3.5 | | | 新增v2辅助工具及继承的 |
| 3.5.1 | | | 优化客户端polyfill及扩展发现机制。 |
Atmosphere包、Meteor npm集成和Rspack核心包的版本相互独立。请检查、和锁文件。更改Meteor版本后,运行,检查npm依赖变更并提交相关文件。不要仅为了复制当前辅助工具,就将较新的集成大版本与较旧的Meteor版本搭配使用。
.meteor/versionspackage.jsonmeteor update --npmDecision flow
决策流程
- Does the app define client and server entry points in
package.json? If no, define them. Required.meteor.mainModule - Trace the client and client-test graphs. Do they reach CommonJS export
assignments, Node built-ins, server-only local package entries, or missing
generated inputs in a clean checkout? If yes, repair the boundary before
activation. See
.
references/client-graph-preflight.md - Does the app code contain nested imports (ES inside an
import, function, or other block)? If yes, move them to top level or convert them to dynamicif/import(). Required for app code; OK in Atmosphere packages.require - Does the app rely on a Meteor build plugin (,
less,fourseven:scss,coffeescript,zodern:melte)? Plan an Rspack loader replacement and prove capability parity before removal. Seejorgenvatle:vite.references/framework-and-css.md - Does the app rely on bare default imports from CommonJS packages
()? Decide between rewriting to
import x from "some-cjs"or restoring Meteor-style interop inimport * as x. See.swcrc.references/code-migrations.md - Is the app server-only? Set only . Rspack still bundles the server; client is skipped.
mainModule.server - Does the app keep CSS or HTML outside its entry folder, or import app-local
symlinks? Preserve the boundary with or
meteor.modules; see the references.resolve.symlinks: false - Run and watch the verbose
meteor add rspacklog for remaining[Transpiler]failures.(app)
- 应用是否在的
package.json中定义了客户端和服务器端入口点?如果没有,请定义它们。此步骤为必填项。meteor.mainModule - 追踪客户端和客户端测试代码图。它们是否引用了CommonJS导出赋值、Node内置模块、仅服务器端的本地包入口,或者在干净检出时缺少生成的输入文件?如果是,请在启用Rspack前修复这些边界问题。请查看。
references/client-graph-preflight.md - 应用代码中是否包含嵌套导入(ES 语句位于
import、函数或其他代码块内部)?如果是,请将其移至顶层,或转换为动态if/import()。应用代码中必须执行此操作;Atmosphere包中则无需修改。require - 应用是否依赖Meteor构建插件(、
less、fourseven:scss、coffeescript、zodern:melte)?请规划使用Rspack loader替代,并在移除原插件前验证功能一致性。请查看jorgenvatle:vite。references/framework-and-css.md - 应用是否依赖从CommonJS包中导入默认导出()?请决定是重写为
import x from "some-cjs",还是在import * as x中恢复Meteor风格的互操作。请查看.swcrc。references/code-migrations.md - 应用是否仅为服务器端应用?请仅设置。Rspack仍会打包服务器端代码;客户端代码将被跳过。
mainModule.server - 应用是否将CSS或HTML文件存放在入口文件夹之外,或者导入应用本地的符号链接?请使用或
meteor.modules保留边界;请查看相关参考文档。resolve.symlinks: false - 运行,并查看详细的
meteor add rspack日志,检查是否存在剩余的[Transpiler]代码失败情况。(app)
Required: entry points
必填项:入口点
json
{
"meteor": {
"mainModule": {
"client": "client/main.js",
"server": "server/main.js"
},
"testModule": "tests.js"
}
}Without , Rspack has no entry. Meteor's eager-loading model
does not apply: Rspack does not auto-discover modules. See
for CSS and HTML routing.
mainModulereferences/framework-and-css.mdjson
{
"meteor": {
"mainModule": {
"client": "client/main.js",
"server": "server/main.js"
},
"testModule": "tests.js"
}
}没有的话,Rspack将没有入口。Meteor的预加载模型不再适用:Rspack不会自动发现模块。有关CSS和HTML的路由,请查看。
mainModulereferences/framework-and-css.mdRequired: no nested imports in app code
必填项:应用代码中禁止嵌套导入
javascript
// app code: NOT allowed under Rspack
if (condition) {
import { a as b } from "./c";
console.log(b);
}Three fixes:
javascript
// 1. Move to top
import { a as b } from "./c";
if (condition) console.log(b);
// 2. Dynamic import (standardized, supported)
if (condition) {
const { a: b } = await import("./c");
console.log(b);
}
// 3. require (CommonJS interop)
if (condition) {
const { a: b } = require("./c");
console.log(b);
}Diagnose with verbose mode and look for files failing with
.
failures are fine; Atmosphere packages are not bundled by Rspack.
(app)Error: 'import' and 'export' cannot be used outside of module code(package)javascript
// 应用代码:Rspack下不允许这样写
if (condition) {
import { a as b } from "./c";
console.log(b);
}三种修复方案:
javascript
// 1. 移至顶层
import { a as b } from "./c";
if (condition) console.log(b);
// 2. 动态导入(标准化,受支持)
if (condition) {
const { a: b } = await import("./c");
console.log(b);
}
// 3. require(CommonJS互操作)
if (condition) {
const { a: b } = require("./c");
console.log(b);
}通过详细模式诊断,查找带有错误的文件。代码的失败无需担心;Atmosphere包不由Rspack打包。
Error: 'import' and 'export' cannot be used outside of module code(app)(package)Required: reserve build folders
必填项:预留构建文件夹
The integration writes to , ,
, . Auto-added to .
If the project already uses any of these names, rename in :
_build/public/build-assets/public/build-chunks/private/build-assets/.gitignorepackage.jsonjson
{
"meteor": {
"buildContext": "build",
"assetsContext": "assets",
"chunksContext": "chunks"
}
}Do not edit any file under those folders. Exclude them from IDE indexing and
from every recursive formatter, linter, typechecker, test-discovery, and
coverage scan. does not configure those tools.
.gitignoreDo not match the active build context in or .
Rspack writes Meteor-facing entry modules there, then Meteor reads them to
assemble the final bundle. Resolve renamed contexts before auditing ignores.
.meteorignoreMETEOR_IGNORE该集成会写入、、、目录。这些目录会自动添加到中。如果项目已使用其中任意名称,请在中重命名:
_build/public/build-assets/public/build-chunks/private/build-assets/.gitignorepackage.jsonjson
{
"meteor": {
"buildContext": "build",
"assetsContext": "assets",
"chunksContext": "chunks"
}
}请勿编辑这些文件夹下的任何文件。将它们排除在IDE索引之外,同时排除在所有递归格式化工具、代码检查工具、类型检查工具、测试发现工具和覆盖率扫描工具之外。不会配置这些工具。
.gitignore请勿在或中匹配当前构建上下文。Rspack会在这些目录中写入面向Meteor的入口模块,然后Meteor读取这些模块来组装最终bundle。在检查忽略规则前,请先解决重命名上下文的问题。
.meteorignoreMETEOR_IGNOREReplacing build plugins
替换构建插件
Most app-file build plugins move to Rspack loaders. Prove capability parity
before removal; make conflicting activation and removal one reversible change.
See .
references/framework-and-css.md| Old plugin | Replacement |
|---|---|
| |
| |
| |
| Official Rspack Svelte loader. |
| Native Rspack Vue/Solid loaders. |
| Babel via Rspack loader on |
| Still compatible. Keep it. |
Plugins acting only on Atmosphere package files can stay. Plugins acting on
app-folder files (entry folder excluded) must move to Rspack.
大多数应用文件构建插件可替换为Rspack loader。在移除原插件前,请验证功能一致性;将冲突的激活和移除操作作为一个可回滚的变更。请查看。
references/framework-and-css.md| 旧插件 | 替代方案 |
|---|---|
| |
| |
| |
| 官方Rspack Svelte loader。 |
| 原生Rspack Vue/Solid loader。 |
| 通过Rspack loader在 |
| 仍兼容,请保留。 |
仅作用于Atmosphere包文件的插件可保留。作用于应用文件夹文件(入口文件夹除外)的插件必须替换为Rspack loader。
CommonJS default-import interop
CommonJS默认导入互操作
Old Meteor accepted for a
package. Rspack + SWC do not by default. Two options:
import x from "some-cjs-lib"module.exports = ...javascript
// preferred: switch to namespace import
import * as x from "some-cjs-lib";Or restore interop in :
.swcrcjson
{
"module": {
"type": "commonjs",
"noInterop": false,
"importInterop": "node"
}
}This emits CommonJS, defeating tree-shaking and static analysis app-wide.
Migrate imports instead unless you cannot.
旧版Meteor允许对的包使用语法。而Rspack + SWC默认不支持此语法。有两种选择:
module.exports = ...import x from "some-cjs-lib"javascript
// 推荐:切换为命名空间导入
import * as x from "some-cjs-lib";或者在中恢复互操作:
.swcrcjson
{
"module": {
"type": "commonjs",
"noInterop": false,
"importInterop": "node"
}
}这会生成CommonJS代码,破坏整个应用的树摇优化和静态分析能力。除非万不得已,否则请迁移导入语句。
CI and Docker
CI与Docker
After upgrading Meteor locally, the required npm bumps must be committed.
If they are not, CI/Docker builds fail with:
text
Could not find rspack.config.js, rspack.config.ts, rspack.config.mjs, or rspack.config.cjsPreferred reproducible flow:
- Run locally after changing the Meteor release.
meteor update --npm - Commit and the lockfile.
package.json - Run followed by
meteor npm ciin CI.meteor build
See for the recovery-only Docker fallback when
a pipeline intentionally repairs missing npm bumps during the build.
references/troubleshooting.md在本地升级Meteor后,必须提交所需的npm依赖更新。如果未提交,CI/Docker构建会失败并提示:
text
Could not find rspack.config.js, rspack.config.ts, rspack.config.mjs, or rspack.config.cjs推荐的可复现流程:
- 更改Meteor版本后,在本地运行。
meteor update --npm - 提交和锁文件。
package.json - 在CI中运行,然后执行
meteor npm ci。meteor build
当流水线需要在构建过程中自动修复缺失的npm依赖更新时,请查看中的Docker回退方案。
references/troubleshooting.mdAnti-patterns
反模式
- Add Rspack before fixing Babel fallbacks. Find them with
and fix them while still on the optimization-only stack.
"meteor": { "modern": { "transpiler": { "verbose": true } } } - Restore CJS interop globally in to avoid migrating a handful of imports. Trades real bundle-size wins for short-term convenience.
.swcrc - Commit ,
_build/,public/build-assets/,public/build-chunks/. Autogenerated.private/build-assets/ - Change the Meteor release without running and committing its npm dependency changes. A stale lockfile makes clean CI builds fail or pick an incompatible integration major.
meteor update --npm
- 在修复Babel回退问题前就添加Rspack。可通过找到这些问题,并在仍处于仅优化栈时修复它们。
"meteor": { "modern": { "transpiler": { "verbose": true } } } - 在中全局恢复CJS互操作,以避免迁移少量导入语句。这是以牺牲真实的包体积优化为代价换取短期便利。
.swcrc - 提交、
_build/、public/build-assets/、public/build-chunks/目录。这些是自动生成的文件。private/build-assets/ - 更改Meteor版本后,未运行并提交npm依赖变更。过时的锁文件会导致干净的CI构建失败,或选择不兼容的集成大版本。
meteor update --npm
See also
另请参阅
references/code-migrations.mdreferences/client-graph-preflight.mdreferences/validation-matrix.mdreferences/framework-and-css.mdreferences/troubleshooting.mdreferences/eval-cases.md- For setup, helpers, and API:
rspack.config.js.meteor-modern-build-stack
references/code-migrations.mdreferences/client-graph-preflight.mdreferences/validation-matrix.mdreferences/framework-and-css.mdreferences/troubleshooting.mdreferences/eval-cases.md- 如需设置、辅助工具和API相关内容,请查看
rspack.config.js。meteor-modern-build-stack