unplugin-vue-complex-types
v0.3.0
Published
Resolve complex types in Vue SFCs.
Downloads
9
Maintainers
Readme
unplugin-vue-complex-types
Use @vue/language-core
to support complex types for Vue Macros.
For example: fixes https://github.com/vuejs/core/issues/8286.
📦 Installation
$ npm install -D unplugin-vue-complex-types
$ yarn add -D unplugin-vue-complex-types
$ pnpm add -D unplugin-vue-complex-types
TODOs
- [ ] Add more tests
🚀 Usage
// vite.config.ts
import VueComplexTypes from "unplugin-vue-complex-types/vite";
export default defineConfig({
plugins: [
VueComplexTypes({
/* options */
}),
],
});
// rollup.config.js
import VueComplexTypes from "unplugin-vue-complex-types/rollup";
export default {
plugins: [
VueComplexTypes({
/* options */
}),
// other plugins
],
};
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require("unplugin-vue-complex-types/webpack")({
/* options */
}),
],
};
// rspack.config.js
module.exports = {
/* ... */
plugins: [
require("unplugin-vue-complex-types/rspack")({
/* options */
}),
],
};
// nuxt.config.ts
export default defineNuxtConfig({
modules: ["unplugin-vue-complex-types/nuxt"],
complexTypes: {
/* options */
},
});
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require("unplugin-vue-complex-types/webpack")({
/* options */
}),
],
},
};
// quasar.conf.js [Vite]
module.exports = {
vitePlugins: [
[
"unplugin-vue-complex-types/vite",
{
/* options */
},
],
],
};
// quasar.conf.js [Webpack]
const VueComplexTypesPlugin = require("unplugin-vue-complex-types/webpack");
module.exports = {
build: {
chainWebpack(chain) {
chain.plugin("unplugin-vue-complex-types").use(
VueComplexTypesPlugin({
/* options */
}),
);
},
},
};
// esbuild.config.js
import { build } from "esbuild";
build({
/* ... */
plugins: [
require("unplugin-vue-complex-types/esbuild")({
/* options */
}),
],
});
// astro.config.mjs
import VueComplexTypes from "unplugin-vue-complex-types/astro";
export default defineConfig({
integrations: [
VueComplexTypes({
/* options */
}),
],
});
📚 Options
tsconfigPath
- Type:
string
- Default:
path.join(process.cwd(), "tsconfig.json")
🖥️ How it works?
This plugin parses each SFC and traverse <script setup lang="ts">
's AST to find defineProps
's type argument and use TypeScript's type checker API to print the resolved type, then we overwrite the original type with the resolved type. Thus Vue's compiler can generate correct runtime code without parsing the complex types.