Skip to content

Commit fa4ba28

Browse files
authored
feat(plugin-vue): support text import attributes (#8053)
1 parent 7816fb7 commit fa4ba28

7 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { readFileSync } from 'node:fs';
2+
import { join } from 'node:path';
3+
import { expect, test } from '@e2e/helper';
4+
5+
test('should import Vue SFC as text with import attributes', async ({ page, runBothServe }) => {
6+
await runBothServe(async () => {
7+
expect(await page.evaluate('window.vueText')).toBe(
8+
readFileSync(join(import.meta.dirname, './src/App.vue'), 'utf-8'),
9+
);
10+
await expect(page.locator('#normal-vue')).toHaveText('Normal Vue SFC');
11+
});
12+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from '@rsbuild/core';
2+
import { pluginVue } from '@rsbuild/plugin-vue';
3+
4+
export default defineConfig({
5+
plugins: [pluginVue()],
6+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<div class="text-source">Vue text import</div>
3+
</template>
4+
5+
<script setup>
6+
const message = 'raw source should keep script content';
7+
</script>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<div id="normal-vue">Normal Vue SFC</div>
3+
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { createApp } from 'vue';
2+
import text from './App.vue' with { type: 'text' };
3+
import Normal from './Normal.vue';
4+
5+
window.vueText = text;
6+
7+
createApp(Normal).mount('#root');

packages/plugin-vue/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,22 @@ export function pluginVue(options: PluginVueOptions = {}): RsbuildPlugin {
112112
compilerOptions,
113113
};
114114

115+
// TODO: Use a oneOf-based rule structure in the next major version
115116
chain.module
116117
.rule(CHAIN_ID.RULE.VUE)
117118
.test(test)
119+
.with({ type: { not: 'text' } })
118120
.use(CHAIN_ID.USE.VUE)
119121
.loader(require.resolve('rspack-vue-loader'))
120122
.options(vueLoaderOptions);
121123

124+
chain.module
125+
.rule('vue-text')
126+
.after(CHAIN_ID.RULE.VUE)
127+
.test(test)
128+
.with({ type: 'text' })
129+
.type('asset/source');
130+
122131
// Support for lang="postcss" and lang="pcss" in SFC
123132
chain.module.rule(CHAIN_ID.RULE.CSS).test(/\.(?:css|postcss|pcss)$/);
124133

packages/plugin-vue/tests/__snapshots__/index.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ exports[`plugin-vue > should add vue-loader and VueLoaderPlugin correctly 1`] =
1515
},
1616
},
1717
],
18+
"with": {
19+
"type": {
20+
"not": "text",
21+
},
22+
},
1823
}
1924
`;
2025

@@ -53,6 +58,11 @@ exports[`plugin-vue > should allow to configure vueLoader options 1`] = `
5358
},
5459
},
5560
],
61+
"with": {
62+
"type": {
63+
"not": "text",
64+
},
65+
},
5666
}
5767
`;
5868

@@ -71,6 +81,11 @@ exports[`plugin-vue > should allow to custom test condition 1`] = `
7181
},
7282
},
7383
],
84+
"with": {
85+
"type": {
86+
"not": "text",
87+
},
88+
},
7489
}
7590
`;
7691

0 commit comments

Comments
 (0)