feat: 新增 jsx/tsx 支持

This commit is contained in:
hxr 2023-10-22 00:03:41 +08:00
parent 723199545c
commit a7e79341d7
4 changed files with 50 additions and 3 deletions

View File

@ -77,6 +77,7 @@
"@types/stompjs": "^2.3.5",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"@vitejs/plugin-vue-jsx": "^3.0.2",
"autoprefixer": "^10.4.14",
"commitizen": "^4.3.0",
"cz-git": "^1.6.1",

View File

@ -0,0 +1,41 @@
<script setup lang="ts">
import SvgIcon from "@/components/SvgIcon/index.vue";
import { translateRouteTitle } from "@/utils/i18n";
const props = defineProps({
icon: {
type: String,
default: "",
},
title: {
type: String,
default: "",
},
});
const vnodes: any[] = [];
if (props.icon) {
if (props.icon.includes("el-icon")) {
vnodes.push(h("i", { class: [props.icon, "sub-el-icon"] }));
} else {
vnodes.push(h(SvgIcon, { "icon-class": props.icon }));
}
}
if (props.title) {
vnodes.push(h("span", { slot: "title" }, translateRouteTitle(props.title)));
}
const render = h("div", vnodes);
</script>
<template>
<render />
</template>
<style scoped>
.sub-el-icon {
width: 1em;
height: 1em;
color: currentcolor;
}
</style>

View File

@ -6,7 +6,6 @@
"moduleResolution": "node",
"strict": true,
"noLib": false,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
@ -19,7 +18,11 @@
"types": ["vite/client", "unplugin-icons/types/vue"],
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"allowSyntheticDefaultImports": true /* */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"jsx": "preserve",
"jsxFactory": "h",
"jsxFragmentFactory": "Fragment"
},
"include": [
"src/**/*.ts",
@ -29,5 +32,4 @@
"vite.config.ts"
],
"exclude": ["node_modules", "dist", "**/*.js"]
// "references": [{ "path": "./tsconfig.node.json" }]
}

View File

@ -13,6 +13,8 @@ import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import { viteMockServe } from "vite-plugin-mock";
import vueJsx from "@vitejs/plugin-vue-jsx";
import UnoCSS from "unocss/vite";
import path from "path";
@ -67,6 +69,7 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
},
plugins: [
vue(),
vueJsx(),
UnoCSS({
hmrTopLevelAwait: false,
}),