From 7607a4e1939ac6d87aba77f1eea78c016e657e81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B3=A2=E6=AF=94=E5=B0=8F=E9=87=91=E5=88=9A?= <2890636389@qq.com> Date: Tue, 24 Dec 2024 14:12:49 +0800 Subject: [PATCH 1/4] fix: Rspack cssParser will parse failed when url(' ') (#8824) fix: parsing process for handling strings with multiple spaces Co-authored-by: bobihuang --- crates/rspack_plugin_css/src/parser_and_generator/mod.rs | 2 +- .../plugin-css/simple-url/__snapshots__/output.snap.txt | 7 +++++++ .../tests/builtinCases/plugin-css/simple-url/index.js | 1 + .../tests/builtinCases/plugin-css/simple-url/style.css | 3 +++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/__snapshots__/output.snap.txt create mode 100644 packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/index.js create mode 100644 packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/style.css diff --git a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs index cdca4895fcb..00cbcd3be06 100644 --- a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs @@ -164,7 +164,7 @@ impl ParserAndGenerator for CssParserAndGenerator { range, kind, } => { - if request.is_empty() { + if request.trim().is_empty() { continue; } let request = replace_module_request_prefix( diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/__snapshots__/output.snap.txt new file mode 100644 index 00000000000..c58d966b87a --- /dev/null +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/__snapshots__/output.snap.txt @@ -0,0 +1,7 @@ +```css title=main.css +body { + background: red url(' '); +} + + +``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/index.js b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/index.js new file mode 100644 index 00000000000..4fe51c72d64 --- /dev/null +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/index.js @@ -0,0 +1 @@ +import "./style.css"; diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/style.css b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/style.css new file mode 100644 index 00000000000..328d5ecda4e --- /dev/null +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/style.css @@ -0,0 +1,3 @@ +body { + background: red url(' '); +} From d87bd863938053464e43eb2759b9340b02ca54e5 Mon Sep 17 00:00:00 2001 From: hardfist Date: Tue, 24 Dec 2024 14:14:41 +0800 Subject: [PATCH 2/4] chore: split canary to separate scope (#8828) --- .github/workflows/release-canary.yml | 2 +- scripts/release/version.mjs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-canary.yml b/.github/workflows/release-canary.yml index 45678e541bb..b25df65e48d 100644 --- a/.github/workflows/release-canary.yml +++ b/.github/workflows/release-canary.yml @@ -88,4 +88,4 @@ jobs: ./x publish snapshot --tag canary env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + NPM_TOKEN: ${{ secrets.RSPACK_CANARY_RELEASE_TOKEN }} diff --git a/scripts/release/version.mjs b/scripts/release/version.mjs index 419a90bfbf6..09f30e39a64 100644 --- a/scripts/release/version.mjs +++ b/scripts/release/version.mjs @@ -20,7 +20,10 @@ export function getNextName(name) { if (["monorepo"].includes(name)) { return name; } - const nextName = `${name}-canary`; + if (name === "create-rspack") { + return "create-rspack-canary"; + } + const nextName = name.replace(/^@rspack/, "@rspack-canary"); return nextName; } From 3c93b212a926aca8471122d545baee0f88d3a411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B3=A2=E6=AF=94=E5=B0=8F=E9=87=91=E5=88=9A?= <2890636389@qq.com> Date: Tue, 24 Dec 2024 15:26:42 +0800 Subject: [PATCH 3/4] docs: update output.clean type declaration (#8826) * docs: Update output.clean type declaration * docs: add example for output.clean.keep * Apply suggestions from code review --------- Co-authored-by: neverland --- website/docs/en/config/output.mdx | 9 ++++++++- website/docs/zh/config/output.mdx | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/website/docs/en/config/output.mdx b/website/docs/en/config/output.mdx index 1569a6cc581..807dc862fb0 100644 --- a/website/docs/en/config/output.mdx +++ b/website/docs/en/config/output.mdx @@ -154,7 +154,7 @@ module.exports = { ## output.clean -- **Type:** `boolean` +- **Type:** `boolean | { keep?: string }` - **Default:** `false` Before generating the products, delete all files in the output directory. @@ -165,6 +165,13 @@ module.exports = { output: { clean: true, // Clean the output directory before emit. }, + + // or + output: { + clean: { + keep: 'ignored/dir', // keep these assets under 'dist/ignored/dir'. + }, + }, }; ``` diff --git a/website/docs/zh/config/output.mdx b/website/docs/zh/config/output.mdx index f98c3622fc9..f5e19a20dd4 100644 --- a/website/docs/zh/config/output.mdx +++ b/website/docs/zh/config/output.mdx @@ -150,7 +150,7 @@ module.exports = { ## output.clean -- **类型:** `boolean` +- **类型:** `boolean | { keep?: string }` - **默认值:** `false` 在生成产物前,删除输出目录下的所有文件。 @@ -161,6 +161,13 @@ module.exports = { output: { clean: true, // Clean the output directory before emit. }, + + // or + output: { + clean: { + keep: 'ignored/dir', // keep these assets under 'dist/ignored/dir'. + }, + }, }; ``` From 26dc3b841933f7999aab198321500d61cff2fa5f Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 24 Dec 2024 16:10:10 +0800 Subject: [PATCH 4/4] docs: add FAQ for SWC plugin version unmatched (#8829) --- website/docs/en/errors/swc-plugin-version.mdx | 25 +++++++++++++++++++ .../en/guide/features/builtin-swc-loader.mdx | 3 ++- website/docs/zh/errors/swc-plugin-version.mdx | 25 +++++++++++++++++++ .../zh/guide/features/builtin-swc-loader.mdx | 4 ++- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 website/docs/en/errors/swc-plugin-version.mdx create mode 100644 website/docs/zh/errors/swc-plugin-version.mdx diff --git a/website/docs/en/errors/swc-plugin-version.mdx b/website/docs/en/errors/swc-plugin-version.mdx new file mode 100644 index 00000000000..88dbd7a1bd0 --- /dev/null +++ b/website/docs/en/errors/swc-plugin-version.mdx @@ -0,0 +1,25 @@ +# SWC Plugin Version Unmatched + +## Why This Error Occurred + +The SWC plugin is still an experimental feature, and the SWC Wasm plugin is currently not backward compatible. The version of the SWC plugin is closely tied to the version of `swc_core` that Rspack depends on. + +This means that you must to choose an SWC plugin that matches the current version of `swc_core` to ensure that it works properly. If the version of the SWC plugin you are using does not match the version of `swc_core` that Rspack depends on, Rspack will throw the following error during the build process: + +```text +The version of the SWC Wasm plugin you're using might not be compatible with 'builtin:swc-loader' +``` + +## Possible Ways to Fix It + +If you encounter the above issues, a common solution is to upgrade both the Rspack and SWC plugins to the latest versions. + +Alternatively, you can follow these steps to select a suitable SWC plugin version: + +1. Check the current version of [@rspack/core](https://www.npmjs.com/package/@rspack/core) you are using. +2. Visit [plugins.swc.rs](https://plugins.swc.rs/) and select the version of Rspack you are currently using. +3. The website will list the range of SWC plugin versions that match to your current Rspack version. Then select the matched version of the SWC plugin to use. + +If the SWC plugin you are using is not listed on [plugins.swc.rs](https://plugins.swc.rs/), you can find the version information of `swc_core` in the Cargo.toml file within the Rust code repository. + +For example, in the Rspack repository, you can open [Cargo.toml](https://github.com/web-infra-dev/rspack/blob/main/Cargo.toml) and search for the keyword `swc_core` to find the version. Then read [SWC - Selecting the version](https://swc.rs/docs/plugin/selecting-swc-core) for further guidance. diff --git a/website/docs/en/guide/features/builtin-swc-loader.mdx b/website/docs/en/guide/features/builtin-swc-loader.mdx index 2a985e0908a..9b7f3773677 100644 --- a/website/docs/en/guide/features/builtin-swc-loader.mdx +++ b/website/docs/en/guide/features/builtin-swc-loader.mdx @@ -225,7 +225,8 @@ The following is an introduction to some SWC configurations and Rspack specific :::warning The Wasm plugin is deeply coupled with the version of SWC, you need to choose a Wasm plugin that is compatible with the corresponding version of SWC in order to function normally. -you can see more compatible info about how to choose right Wasm plugin version in [selecting-swc-core](https://swc.rs/docs/plugin/selecting-swc-core#088x--089x). + +See [FAQ - SWC Plugin Version Unmatched](/errors/swc-plugin-version) for more details. ::: Rspack supports load Wasm plugin in `builtin:swc-loader`, you can specify the plugin name like diff --git a/website/docs/zh/errors/swc-plugin-version.mdx b/website/docs/zh/errors/swc-plugin-version.mdx new file mode 100644 index 00000000000..a87898b3228 --- /dev/null +++ b/website/docs/zh/errors/swc-plugin-version.mdx @@ -0,0 +1,25 @@ +# SWC 插件版本不匹配 + +## 错误出现的原因 + +SWC 的插件仍然是一个实验性功能,目前 SWC 的 Wasm 插件是不向后兼容的,SWC 插件的版本与 Rspack 依赖的 `swc_core` 版本存在强耦合关系。 + +这意味着,你需要选择和当前 `swc_core` 版本匹配的 SWC 插件,才能使它正常执行。如果你使用的 SWC 插件版本与 Rspack 依赖的 `swc_core` 版本不匹配,Rspack 在执行构建时会抛出如下错误: + +```text +The version of the SWC Wasm plugin you're using might not be compatible with 'builtin:swc-loader' +``` + +## 可能的修复方式 + +如果你遇到了以上问题,通常可行的解决方法是将 Rspack 和 SWC 插件都升级到最新版本。 + +此外,你也可以按照以下步骤来选择合适的 SWC 插件版本: + +1. 查看当前使用的 [@rspack/core](https://www.npmjs.com/package/@rspack/core) 版本。 +2. 访问 [plugins.swc.rs](https://plugins.swc.rs/),选择你当前使用的 Rspack 版本。 +3. 该网站会列出你当前使用的 Rspack 版本所匹配的 SWC 插件版本范围,选择匹配的 SWC 插件版本使用即可。 + +如果你使用的 SWC 插件未收录到 [plugins.swc.rs](https://plugins.swc.rs/),你可以通过 Rust 代码仓库中的 Cargo.toml 文件来查看 `swc_core` 的版本信息。 + +以 Rspack 仓库为例,你可以打开 [Cargo.toml](https://github.com/web-infra-dev/rspack/blob/main/Cargo.toml),搜索 `swc_core` 关键字来查看版本,然后参考 [SWC - Selecting the version](https://swc.rs/docs/plugin/selecting-swc-core) 进行选择。 diff --git a/website/docs/zh/guide/features/builtin-swc-loader.mdx b/website/docs/zh/guide/features/builtin-swc-loader.mdx index efac148ad36..c2d7eff5d77 100644 --- a/website/docs/zh/guide/features/builtin-swc-loader.mdx +++ b/website/docs/zh/guide/features/builtin-swc-loader.mdx @@ -224,7 +224,9 @@ export default { :::warning -Wasm 插件和 SWC 的版本存在一定的绑定关系,需要选择和对应 SWC 版本兼容的 Wasm 插件才能正常执行, [selecting-swc-core](https://swc.rs/docs/plugin/selecting-swc-core#088x--089x) 里有更多关于如何选择兼容的 Wasm 插件的信息。 +Wasm 插件和 SWC 的版本存在一定的绑定关系,需要选择和对应 SWC 版本兼容的 Wasm 插件才能正常执行。 + +详见 [常见问题 - SWC 插件版本不匹配](/errors/swc-plugin-version)。 ::: Rspack 支持在 `builtin:swc-loader` 里加载 SWC 的 Wasm 插件, 你可以通过如下配置启用 Wasm 插件