import path from "path";
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import Vue from "@vitejs/plugin-vue";
import { name } from "./package.json";
import externals from "rollup-plugin-node-externals";
import dts from "vite-plugin-dts";
export default defineConfig({
plugins: [Vue(), externals(), dts()],
build: {
lib: {
entry: path.resolve(__dirname, "src/index.ts"),
name,
formats: ["es", "umd", "cjs"],
fileName: (format) => `${name}.${format}.js`,
},
rollupOptions: {
external: ["vue", "element-plus"],
output: {
globals: {
vue: "Vue",
},
assetFileNames: (assetInfo): string => {
if (assetInfo.name === "style.css") {
return `${name}.components.css`;
}
return assetInfo.name as string;
},
exports: "named",
},
},
},
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
});
import type { App } from "vue";
import * as components from "./components";
function install(app: App) {
for (const key in components) {
app.component(key, components[key]);
}
}
export default { install };
export * from "./components";
import ComponentA from "./a/a.vue";
import ComponentB from "./b/b.vue";
import ComponentC from "./c/c.vue";
export { ComponentA, ComponentB, ComponentC };
<script lang="ts">
import { defineComponent, ref } from "vue";
export default defineComponent({
name: "ComponentA",
props: {
min: {
required: false,
type: Number,
default: 0,
},
max: {
required: false,
type: Number,
default: 1000,
},
},
data() {
return {
value: ref([this.min, this.max]),
};
},
methods: {
onChange(e: any) {
console.log(e);
},
},
});
</script>