
Security News
Cloudflare Introduces a Faster TypeScript Compiler Written in Rust
Cloudflare introduces tsrs, a Rust port of TypeScript’s compiler promising faster checks and lower memory use, with the TypeScript team’s help.
vitejs-plugin-vue-setup-extend
Advanced tools
为 Vue 3 `<script setup>` 语法扩展支持定义组件的 `name` 和 `inheritAttrs` 属性的 Vite 插件。
为 Vue 3 <script setup> 语法扩展支持定义组件的 name 和 inheritAttrs 属性。
相较于 vite-plugin-vue-setup-extend 和 vite-plugin-vue-setup-extend-plus,本插件专门解决了在使用 TypeScript 时的一个常见问题:
当组件的 Props 类型定义在单独的文件中并使用 import 引入时,其他插件可能会出现编译错误。本插件则是避免了这一问题。
npm install vitejs-plugin-vue-setup-extend -D
# or
yarn add vitejs-plugin-vue-setup-extend -D
# or
pnpm add vitejs-plugin-vue-setup-extend -D
在 vite.config.js 中添加插件:
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueSetupExtend from "vitejs-plugin-vue-setup-extend";
export default defineConfig({
plugins: [vue(), vueSetupExtend()],
});
// type.ts
export interface Props {
param1: string;
param2: number;
}
<template>
<div>{{ param1 }}: {{ param2 }}</div>
</template>
<script setup lang="ts" name="MyComponent" inheritAttrs="false">
import type { Props } from "./type";
import { ref } from "vue";
defineProps<Props>();
const data = ref("MyComponent");
</script>
插件会自动将上述 vue 代码转换为:
<script lang="ts">
export default {
name: "MyComponent",
inheritAttrs: false,
};
</script>
<template>
<div>{{ param1 }}: {{ param2 }}</div>
</template>
<script setup lang="ts" name="MyComponent" inheritAttrs="false">
import type { Props } from "./type";
import { ref } from "vue";
defineProps<Props>();
const data = ref("MyComponent");
</script>
插件支持以下配置选项:
vueSetupExtend({
include: ["./src/**"], // 包含的文件模式,默认为 ["./src/**"]
exclude: [], // 排除的文件模式
});
FAQs
为 Vue 3 `<script setup>` 语法扩展支持定义组件的 `name` 和 `inheritAttrs` 属性的 Vite 插件。
The npm package vitejs-plugin-vue-setup-extend receives a total of 0 weekly downloads. As such, vitejs-plugin-vue-setup-extend popularity was classified as not popular.
We found that vitejs-plugin-vue-setup-extend demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Security News
Cloudflare introduces tsrs, a Rust port of TypeScript’s compiler promising faster checks and lower memory use, with the TypeScript team’s help.

Security News
The PHP Foundation says Chainguard broke a security embargo ahead of critical RCE patches, as leaks disrupted the coordinated release.

Security News
PHP releases emergency patches for two critical RCE vulnerabilities as agencies urge organizations to take unpatched sites offline.