-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: JSX support has been adjusted - Default JSX support is now configured for Vue 3 JSX - `jsx` option now accepts string presets ('vue' | 'preact' | 'react') e.g. to Use Preact with Vite, use `vite --jsx preact`. In addition, when using the Preact preset, Vite auto injects `h` import in `.jsx` and `.tsx` files so the user no longer need to import it.
- Loading branch information
Showing
12 changed files
with
138 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { h } from 'preact' | ||
|
||
export function Test(props: { count: 0 }) { | ||
return <div>Rendered from TSX: count is {props.count}</div> | ||
return <div>Rendered from Preact TSX: count is {props.count}</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createVNode } from 'vue' | ||
|
||
declare const __DEV__: boolean | ||
|
||
if (__DEV__) { | ||
console.log( | ||
`[vue tip] You are using an non-optimized version of Vue 3 JSX, ` + | ||
`which does not take advantage of Vue 3's runtime fast paths. An improved ` + | ||
`JSX transform will be provided at a later stage.` | ||
) | ||
} | ||
|
||
export function jsx(tag: any, props = null) { | ||
const c = | ||
arguments.length > 2 ? Array.prototype.slice.call(arguments, 2) : null | ||
return createVNode(tag, props, typeof tag === 'string' ? c : () => c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
import { ServerPlugin } from '.' | ||
import { tjsxRE, transform } from '../esbuildService' | ||
import { readBody, genSourceMapString } from '../utils' | ||
import { | ||
tjsxRE, | ||
transform, | ||
reoslveJsxOptions, | ||
vueJsxPublicPath, | ||
vueJsxFilePath | ||
} from '../esbuildService' | ||
import { readBody, genSourceMapString, cachedRead } from '../utils' | ||
|
||
export const esbuildPlugin: ServerPlugin = ({ app, config }) => { | ||
const options = { | ||
jsxFactory: config.jsx && config.jsx.factory, | ||
jsxFragment: config.jsx && config.jsx.fragment | ||
} | ||
const jsxConfig = reoslveJsxOptions(config.jsx) | ||
|
||
app.use(async (ctx, next) => { | ||
// intercept and return vue jsx helper import | ||
if (ctx.path === vueJsxPublicPath) { | ||
await cachedRead(ctx, vueJsxFilePath) | ||
} | ||
|
||
await next() | ||
|
||
if (ctx.body && tjsxRE.test(ctx.path)) { | ||
ctx.type = 'js' | ||
const src = await readBody(ctx.body) | ||
const { code, map } = await transform(src!, ctx.path, options) | ||
let res = code | ||
let { code, map } = await transform(src!, ctx.path, jsxConfig, config.jsx) | ||
if (map) { | ||
res += genSourceMapString(map) | ||
code += genSourceMapString(map) | ||
} | ||
ctx.body = res | ||
ctx.body = code | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters