@vitejs/plugin-vue-jsx
Advanced tools
+9
-0
@@ -0,1 +1,10 @@ | ||
| # [1.1.0](https://github.com/vitejs/vite/compare/plugin-vue-jsx@1.0.3...plugin-vue-jsx@1.1.0) (2021-02-09) | ||
| ### Features | ||
| * **plugin-vue-jsx:** register jsx module during ssr ([7a6aa2a](https://github.com/vitejs/vite/commit/7a6aa2ad2689bf8221389924a608876866db7b0a)) | ||
| ## [1.0.3](https://github.com/vitejs/vite/compare/plugin-vue-jsx@1.0.2...plugin-vue-jsx@1.0.3) (2021-02-08) | ||
@@ -2,0 +11,0 @@ |
+67
-20
@@ -7,3 +7,26 @@ // @ts-check | ||
| const ssrRegisterHelperId = '/__vue-jsx-ssr-register-helper' | ||
| const ssrRegisterHelperCode = | ||
| `import { useSSRContext } from "vue"\n` + | ||
| `export ${ssrRegisterHelper.toString()}` | ||
| /** | ||
| * This function is serialized with toString() and evaluated as a virtual | ||
| * module during SSR | ||
| * @param {import('vue').ComponentOptions} comp | ||
| * @param {string} filename | ||
| */ | ||
| function ssrRegisterHelper(comp, filename) { | ||
| const setup = comp.setup | ||
| comp.setup = (props, ctx) => { | ||
| // @ts-ignore | ||
| const ssrContext = useSSRContext() | ||
| ;(ssrContext.modules || (ssrContext.modules = new Set())).add(filename) | ||
| if (setup) { | ||
| return setup(props, ctx) | ||
| } | ||
| } | ||
| } | ||
| /** | ||
| * @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions} options | ||
@@ -39,2 +62,14 @@ * @returns {import('vite').Plugin} | ||
| resolveId(id) { | ||
| if (id === ssrRegisterHelperId) { | ||
| return id | ||
| } | ||
| }, | ||
| load(id) { | ||
| if (id === ssrRegisterHelperId) { | ||
| return ssrRegisterHelperCode | ||
| } | ||
| }, | ||
| transform(code, id, ssr) { | ||
@@ -58,3 +93,3 @@ if (/\.[jt]sx$/.test(id)) { | ||
| if (ssr || !needHmr) { | ||
| if (!ssr && !needHmr) { | ||
| return { | ||
@@ -149,24 +184,36 @@ code: result.code, | ||
| if (hotComponents.length) { | ||
| let code = result.code | ||
| if (hasDefault) { | ||
| code = | ||
| code.replace( | ||
| /export default defineComponent/g, | ||
| `const __default__ = defineComponent` | ||
| ) + `\nexport default __default__` | ||
| if (needHmr && !ssr) { | ||
| let code = result.code | ||
| if (hasDefault) { | ||
| code = | ||
| code.replace( | ||
| /export default defineComponent/g, | ||
| `const __default__ = defineComponent` | ||
| ) + `\nexport default __default__` | ||
| } | ||
| let callbackCode = `` | ||
| for (const { local, exported, id } of hotComponents) { | ||
| code += | ||
| `\n${local}.__hmrId = "${id}"` + | ||
| `\n__VUE_HMR_RUNTIME__.createRecord("${id}", ${local})` | ||
| callbackCode += `\n__VUE_HMR_RUNTIME__.reload("${id}", __${exported})` | ||
| } | ||
| code += `\nimport.meta.hot.accept(({${hotComponents | ||
| .map((c) => `${c.exported}: __${c.exported}`) | ||
| .join(',')}}) => {${callbackCode}\n})` | ||
| result.code = code | ||
| } | ||
| let callbackCode = `` | ||
| for (const { local, exported, id } of hotComponents) { | ||
| code += | ||
| `\n${local}.__hmrId = "${id}"` + | ||
| `\n__VUE_HMR_RUNTIME__.createRecord("${id}", ${local})` | ||
| callbackCode += `\n__VUE_HMR_RUNTIME__.reload("${id}", __${exported})` | ||
| if (ssr) { | ||
| let ssrInjectCode = | ||
| `\nimport { ssrRegisterHelper } from "${ssrRegisterHelperId}"` + | ||
| `\nconst __moduleId = ${JSON.stringify(id)}` | ||
| for (const { local } of hotComponents) { | ||
| ssrInjectCode += `\nssrRegisterHelper(${local}, __moduleId)` | ||
| } | ||
| result.code += ssrInjectCode | ||
| } | ||
| code += `\nimport.meta.hot.accept(({${hotComponents | ||
| .map((c) => `${c.exported}: __${c.exported}`) | ||
| .join(',')}}) => {${callbackCode}\n})` | ||
| result.code = code | ||
| } | ||
@@ -173,0 +220,0 @@ |
+1
-1
| { | ||
| "name": "@vitejs/plugin-vue-jsx", | ||
| "version": "1.0.3", | ||
| "version": "1.1.0", | ||
| "license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": "Evan You", |
12613
14.54%235
21.76%