Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-vue-jsx): jsx plugin should have extra babel plugins option #3923

Merged
merged 1 commit into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/plugin-vue-jsx/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare interface FilterOptions {
}

declare function createPlugin(
options?: VueJSXPluginOptions & FilterOptions
options?: VueJSXPluginOptions & FilterOptions & { babelPlugins?: any[] }
): Plugin

export default createPlugin
17 changes: 13 additions & 4 deletions packages/plugin-vue-jsx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ function ssrRegisterHelper(comp, filename) {

/**
* @typedef { import('@rollup/pluginutils').FilterPattern} FilterPattern
* @typedef { { include?: FilterPattern, exclude?: FilterPattern } } CommonOtions
* @typedef { { include?: FilterPattern, exclude?: FilterPattern, babelPlugins?: any[] } } CommonOptions
*/

/**
*
* @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions & CommonOtions} options
* @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions & CommonOptions} options
* @returns {import('vite').Plugin}
*/
function vueJsxPlugin(options = {}) {
Expand Down Expand Up @@ -78,12 +78,21 @@ function vueJsxPlugin(options = {}) {
},

transform(code, id, ssr) {
const { include, exclude, ...babelPluginOptions } = options
const {
include,
exclude,
babelPlugins = [],
...babelPluginOptions
} = options

const filter = createFilter(include || /\.[jt]sx$/, exclude)

if (filter(id)) {
const plugins = [importMeta, [jsx, babelPluginOptions]]
const plugins = [
importMeta,
[jsx, babelPluginOptions],
...babelPlugins
]
if (id.endsWith('.tsx')) {
plugins.push([
require('@babel/plugin-transform-typescript'),
Expand Down