Skip to content

Commit

Permalink
feat(plugin-vue): support Vue 3 JSX compilation (#4013)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Jun 20, 2023
1 parent 4a82c3b commit 3223b8b
Show file tree
Hide file tree
Showing 9 changed files with 652 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changeset/kind-ears-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/builder-plugin-vue': patch
---

feat(plugin-vue): support Vue 3 JSX compilation

feat(plugin-vue): 支持编译 Vue 3 JSX
25 changes: 20 additions & 5 deletions packages/builder/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { VueLoaderPlugin } from 'vue-loader';
import type { BuilderPlugin } from '@modern-js/builder';
import type { BuilderPluginAPI } from '@modern-js/builder-webpack-provider';
import type { VueLoaderOptions } from 'vue-loader';
import type { VueJSXPluginOptions } from '@vue/babel-plugin-jsx';

export type PluginVueOptions = {
vueJsxOptions?: VueJSXPluginOptions;
vueLoaderOptions?: VueLoaderOptions;
};

export function builderPluginVue(
options?: PluginVueOptions,
options: PluginVueOptions = {},
): BuilderPlugin<BuilderPluginAPI> {
return {
name: 'builder-plugin-vue',
Expand All @@ -23,9 +25,22 @@ export function builderPluginVue(
],

async setup(api) {
api.modifyBuilderConfig(config => {
config.output ||= {};
config.output.disableSvgr = true;
api.modifyBuilderConfig((config, { mergeBuilderConfig }) => {
return mergeBuilderConfig(config, {
output: {
disableSvgr: true,
},
tools: {
babel(_, { addPlugins }) {
addPlugins([
[
require.resolve('@vue/babel-plugin-jsx'),
options.vueJsxOptions || {},
],
]);
},
},
});
});

api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
Expand All @@ -39,7 +54,7 @@ export function builderPluginVue(
experimentalInlineMatchResource:
api.context.bundlerType === 'rspack',
},
options?.vueLoaderOptions,
options.vueLoaderOptions,
);

chain.module
Expand Down
Loading

0 comments on commit 3223b8b

Please sign in to comment.