feat!: publish per-component ESM entries as @timi/web
Release / release (pull_request) Failing after 2s
Release / release (pull_request) Failing after 2s
This commit is contained in:
+58
-14
@@ -1,4 +1,5 @@
|
||||
import { resolve } from "path";
|
||||
import { existsSync, readdirSync, statSync } from "fs";
|
||||
import { relative, resolve } from "path";
|
||||
import { Alias, defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import VueSetupExtend from "vite-plugin-vue-setup-extend";
|
||||
@@ -9,11 +10,43 @@ import dts from "vite-plugin-dts";
|
||||
|
||||
const alias: Alias[] = [
|
||||
{
|
||||
find: /^timi-web(\/(es|lib))?$/,
|
||||
find: /^@timi\/web(\/(es|lib))?$/,
|
||||
replacement: resolve(__dirname, "./src/index.ts")
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* 递归收集组件入口,用于按组件导出。
|
||||
* 例如 src/components/icon/index.ts -> components/icon/index
|
||||
*/
|
||||
function collectComponentEntries(dir: string, root: string): Record<string, string> {
|
||||
const entries: Record<string, string> = {};
|
||||
|
||||
for (const name of readdirSync(dir)) {
|
||||
const fullPath = resolve(dir, name);
|
||||
|
||||
if (!statSync(fullPath).isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const indexPath = resolve(fullPath, "index.ts");
|
||||
|
||||
if (existsSync(indexPath)) {
|
||||
const entryName = relative(root, indexPath)
|
||||
.replace(/\\/g, "/")
|
||||
.replace(/\.ts$/, "");
|
||||
entries[entryName] = indexPath;
|
||||
} else {
|
||||
Object.assign(entries, collectComponentEntries(fullPath, root));
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
const srcRoot = resolve(__dirname, "src");
|
||||
const componentEntries = collectComponentEntries(resolve(srcRoot, "components"), srcRoot);
|
||||
|
||||
export default defineConfig({
|
||||
server: {
|
||||
port: 3003,
|
||||
@@ -23,22 +56,36 @@ export default defineConfig({
|
||||
alias
|
||||
},
|
||||
build: {
|
||||
target: "es2017",
|
||||
outDir: "dist",
|
||||
lib: {
|
||||
entry: resolve(__dirname, "./src/index.ts"),
|
||||
name: "TimiWeb",
|
||||
fileName: "timi-web"
|
||||
entry: {
|
||||
index: resolve(srcRoot, "index.ts"),
|
||||
"components/index": resolve(srcRoot, "components/index.ts"),
|
||||
"editor/index": resolve(srcRoot, "editor/index.ts"),
|
||||
"utils/index": resolve(srcRoot, "utils/index.ts"),
|
||||
...componentEntries
|
||||
},
|
||||
formats: ["es"],
|
||||
fileName: (_format, entryName) => `${entryName}.js`,
|
||||
cssFileName: "timi-web"
|
||||
},
|
||||
rollupOptions: {
|
||||
external: [
|
||||
"vue"
|
||||
"vue",
|
||||
"@timi/ts",
|
||||
"marked",
|
||||
/^marked-/,
|
||||
"prismjs",
|
||||
/^prismjs\//,
|
||||
/^@tiptap\//,
|
||||
"@marsio/vue-split-pane"
|
||||
],
|
||||
output: {
|
||||
globals: {
|
||||
vue: "Vue"
|
||||
}
|
||||
chunkFileNames: "chunks/[name]-[hash].js"
|
||||
}
|
||||
},
|
||||
cssCodeSplit: false,
|
||||
minify: "terser"
|
||||
},
|
||||
plugins: [
|
||||
@@ -47,11 +94,8 @@ export default defineConfig({
|
||||
}),
|
||||
VueSetupExtend(),
|
||||
dts({
|
||||
// package.json 的 types 与 exports 指向 dist/src/**。
|
||||
// 不显式固定根目录时,插件会按 tsconfig include 推断公共根,
|
||||
// include 一旦变化(例如移除 examples 目录)声明产物就会从
|
||||
// dist/src/** 漂移到 dist/**,进而让所有引用本包类型的地方报错。
|
||||
entryRoot: "."
|
||||
// 按组件导出后,声明文件直接落在 dist/**,与 exports 的路径保持一致。
|
||||
entryRoot: "src"
|
||||
}),
|
||||
prismjsPlugin({
|
||||
languages: [
|
||||
|
||||
Reference in New Issue
Block a user