From 60e7455cead078ffc4d36e7d4e92f60fc6f6bb68 Mon Sep 17 00:00:00 2001 From: xc2 Date: Fri, 19 Apr 2024 00:00:56 +0800 Subject: [PATCH 1/3] test: add style test to vue2 case folder for testing loaders duplicating --- e2e/cases/vue2/sfc-style/index.test.ts | 9 +++++++-- e2e/cases/vue2/sfc-style/src/App.vue | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/e2e/cases/vue2/sfc-style/index.test.ts b/e2e/cases/vue2/sfc-style/index.test.ts index 8c6684c566..43990ae149 100644 --- a/e2e/cases/vue2/sfc-style/index.test.ts +++ b/e2e/cases/vue2/sfc-style/index.test.ts @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; -import { build, gotoPage, rspackOnlyTest } from '@e2e/helper'; +import { build, gotoPage, rspackOnlyTest as test } from '@e2e/helper'; -rspackOnlyTest('should build Vue sfc style correctly', async ({ page }) => { +test('should build Vue sfc style correctly', async ({ page }) => { const rsbuild = await build({ cwd: __dirname, runServer: true, @@ -15,5 +15,10 @@ rspackOnlyTest('should build Vue sfc style correctly', async ({ page }) => { const body = page.locator('body'); await expect(body).toHaveCSS('background-color', 'rgb(0, 0, 255)'); + await expect(body).toHaveCSS( + 'padding', + '-webkit-calc(16px + env(safe-area-inset-bottom))', + ); + await rsbuild.close(); }); diff --git a/e2e/cases/vue2/sfc-style/src/App.vue b/e2e/cases/vue2/sfc-style/src/App.vue index 34564f4245..28ef8186cf 100644 --- a/e2e/cases/vue2/sfc-style/src/App.vue +++ b/e2e/cases/vue2/sfc-style/src/App.vue @@ -12,3 +12,11 @@ export default {}; background-color: green; } + + From bbb989f6154e72326c92c4508061c62efc7f468a Mon Sep 17 00:00:00 2001 From: xc2 Date: Fri, 19 Apr 2024 00:26:49 +0800 Subject: [PATCH 2/3] fix(plugin-vue2): a quick fix for loaders duplicating issue of vue-loader@15 --- e2e/cases/vue2/sfc-style/index.test.ts | 5 +- .../src/VueLoader15PitchFixPlugin.ts | 49 +++++++++++++++++++ packages/plugin-vue2/src/index.ts | 5 ++ packages/shared/src/chain.ts | 2 + 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 packages/plugin-vue2/src/VueLoader15PitchFixPlugin.ts diff --git a/e2e/cases/vue2/sfc-style/index.test.ts b/e2e/cases/vue2/sfc-style/index.test.ts index 43990ae149..03b3777a9f 100644 --- a/e2e/cases/vue2/sfc-style/index.test.ts +++ b/e2e/cases/vue2/sfc-style/index.test.ts @@ -15,10 +15,7 @@ test('should build Vue sfc style correctly', async ({ page }) => { const body = page.locator('body'); await expect(body).toHaveCSS('background-color', 'rgb(0, 0, 255)'); - await expect(body).toHaveCSS( - 'padding', - '-webkit-calc(16px + env(safe-area-inset-bottom))', - ); + await expect(body).toHaveCSS('padding', '16px'); await rsbuild.close(); }); diff --git a/packages/plugin-vue2/src/VueLoader15PitchFixPlugin.ts b/packages/plugin-vue2/src/VueLoader15PitchFixPlugin.ts new file mode 100644 index 0000000000..1d5faa3eb0 --- /dev/null +++ b/packages/plugin-vue2/src/VueLoader15PitchFixPlugin.ts @@ -0,0 +1,49 @@ +import type { Rspack } from '@rsbuild/shared'; + +/** + * this plugin is a quick fix for issue https://github.com/web-infra-dev/rsbuild/issues/2093 + */ +export class VueLoader15PitchFixPlugin implements Rspack.RspackPluginInstance { + readonly name = 'VueLoader15PitchFixPlugin'; + + apply(compiler: Rspack.Compiler) { + const { NormalModule } = compiler.webpack; + compiler.hooks.compilation.tap(this.name, (compilation) => { + const isExpCssOn = compilation.compiler.options?.experiments?.css; + // the related issue only happens when experiments.css is on + if (!isExpCssOn) return; + + NormalModule.getCompilationHooks(compilation).loader.tap( + this.name, + (loaderContext) => { + if ( + // the related issue only happens for