feat!: publish per-component ESM entries as @timi/tdesign-mobile
This commit is contained in:
+52
-17
@@ -1,3 +1,4 @@
|
||||
import { existsSync, readdirSync, statSync } from "fs";
|
||||
import { resolve } from "path";
|
||||
import { Alias, defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
@@ -8,11 +9,44 @@ import dts from "vite-plugin-dts";
|
||||
|
||||
const alias: Alias[] = [
|
||||
{
|
||||
find: /^timi-tdesign-mobile(\/(es|lib))?$/,
|
||||
find: /^@timi\/tdesign-mobile(\/(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"),
|
||||
"directives/index": resolve(__dirname, "./src/directives/index.ts"),
|
||||
"utils/message": resolve(__dirname, "./src/utils/message.ts")
|
||||
};
|
||||
collectComponentEntries(
|
||||
resolve(__dirname, "./src/components"),
|
||||
"components",
|
||||
entries
|
||||
);
|
||||
|
||||
export default defineConfig({
|
||||
server: {
|
||||
port: 3004,
|
||||
@@ -24,33 +58,34 @@ export default defineConfig({
|
||||
build: {
|
||||
outDir: "dist",
|
||||
lib: {
|
||||
entry: resolve(__dirname, "./src/index.ts"),
|
||||
name: "TimiTDesignMobile",
|
||||
fileName: "timi-tdesign-mobile"
|
||||
entry: entries,
|
||||
formats: ["es"],
|
||||
fileName: (_format, entryName) => `${entryName}.js`,
|
||||
cssFileName: "timi-tdesign-mobile"
|
||||
},
|
||||
rollupOptions: {
|
||||
external: [
|
||||
"vue",
|
||||
"vue-router",
|
||||
"timi-web",
|
||||
"tdesign-mobile-vue"
|
||||
],
|
||||
external: (id) =>
|
||||
id === "vue" ||
|
||||
id === "vue-router" ||
|
||||
id === "@timi/web" ||
|
||||
id.startsWith("@timi/web/") ||
|
||||
id === "tdesign-mobile-vue" ||
|
||||
id.startsWith("tdesign-mobile-vue/"),
|
||||
output: {
|
||||
globals: {
|
||||
vue: "Vue",
|
||||
"timi-web": "TimiWeb"
|
||||
}
|
||||
chunkFileNames: "chunks/[name]-[hash].js"
|
||||
}
|
||||
},
|
||||
minify: "terser"
|
||||
cssCodeSplit: false,
|
||||
minify: "terser",
|
||||
target: "es2017"
|
||||
},
|
||||
plugins: [
|
||||
vue({
|
||||
include: [/\.vue$/, /\.md$/]
|
||||
}),
|
||||
dts({
|
||||
pathsToAliases: false,
|
||||
aliasesExclude: [/^timi-web\/editor$/]
|
||||
entryRoot: "src",
|
||||
pathsToAliases: false
|
||||
}),
|
||||
AutoImport({
|
||||
imports: [
|
||||
|
||||
Reference in New Issue
Block a user