129 lines
2.7 KiB
TypeScript
129 lines
2.7 KiB
TypeScript
import { existsSync, readdirSync, statSync } from "fs";
|
|
import { resolve } from "path";
|
|
import { Alias, defineConfig } from "vite";
|
|
import vue from "@vitejs/plugin-vue";
|
|
import VueSetupExtend from "vite-plugin-vue-setup-extend";
|
|
import AutoImport from "unplugin-auto-import/vite";
|
|
import Components from "unplugin-vue-components/vite";
|
|
import { TDesignResolver } from "unplugin-vue-components/resolvers";
|
|
import dts from "vite-plugin-dts";
|
|
|
|
const alias: Alias[] = [
|
|
{
|
|
find: "~",
|
|
replacement: resolve(__dirname, "./src")
|
|
},
|
|
{
|
|
find: /^@timi\/tdesign-pc(\/(es|lib))?$/,
|
|
replacement: resolve(__dirname, "./src/index.ts")
|
|
}
|
|
];
|
|
|
|
/**
|
|
* 递归收集组件入口,组件目录下存在 index.ts 时即视为一个可独立导出的组件
|
|
*/
|
|
function collectComponentEntries(
|
|
dir: string,
|
|
prefix: string,
|
|
entries: Record<string, string>
|
|
) {
|
|
for (const name of readdirSync(dir)) {
|
|
const fullPath = resolve(dir, name);
|
|
if (!statSync(fullPath).isDirectory()) {
|
|
continue;
|
|
}
|
|
const entry = resolve(fullPath, "index.ts");
|
|
if (existsSync(entry)) {
|
|
entries[`${prefix}/${name}/index`] = entry;
|
|
}
|
|
collectComponentEntries(fullPath, `${prefix}/${name}`, entries);
|
|
}
|
|
}
|
|
|
|
const entries: Record<string, string> = {
|
|
index: resolve(__dirname, "./src/index.ts"),
|
|
"components/index": resolve(__dirname, "./src/components/index.ts"),
|
|
"store/popupUser": resolve(__dirname, "./src/store/popupUser.ts")
|
|
};
|
|
collectComponentEntries(
|
|
resolve(__dirname, "./src/components"),
|
|
"components",
|
|
entries
|
|
);
|
|
|
|
export default defineConfig({
|
|
server: {
|
|
port: 3004,
|
|
host: true
|
|
},
|
|
resolve: {
|
|
alias
|
|
},
|
|
build: {
|
|
outDir: "dist",
|
|
lib: {
|
|
entry: entries,
|
|
formats: ["es"],
|
|
fileName: (_format, entryName) => `${entryName}.js`,
|
|
cssFileName: "timi-tdesign-pc"
|
|
},
|
|
rollupOptions: {
|
|
external: (id) =>
|
|
id === "vue" ||
|
|
id === "@timi/web" ||
|
|
id.startsWith("@timi/web/") ||
|
|
id === "tdesign-vue-next" ||
|
|
id.startsWith("tdesign-vue-next/"),
|
|
output: {
|
|
chunkFileNames: "chunks/[name]-[hash].js"
|
|
}
|
|
},
|
|
cssCodeSplit: false,
|
|
minify: "terser",
|
|
target: "es2017",
|
|
terserOptions: {
|
|
compress: {
|
|
// eslint-disable-next-line camelcase
|
|
drop_console: false,
|
|
// eslint-disable-next-line camelcase
|
|
drop_debugger: false
|
|
}
|
|
}
|
|
},
|
|
plugins: [
|
|
vue({
|
|
include: [/\.vue$/, /\.md$/]
|
|
}),
|
|
VueSetupExtend(),
|
|
dts({
|
|
entryRoot: "src",
|
|
pathsToAliases: false
|
|
}),
|
|
AutoImport({
|
|
imports: [
|
|
"vue"
|
|
],
|
|
dts: "auto-imports.d.ts",
|
|
eslintrc: {
|
|
enabled: true,
|
|
globalsPropValue: true
|
|
},
|
|
resolvers: [
|
|
TDesignResolver({
|
|
library: "vue-next"
|
|
})
|
|
]
|
|
}),
|
|
Components({
|
|
dirs: [
|
|
"src/components"
|
|
],
|
|
resolvers: [
|
|
TDesignResolver({
|
|
library: "vue-next"
|
|
})
|
|
]
|
|
})
|
|
]
|
|
});
|