chore: update build process to improve type generation and configuration
This commit is contained in:
+31
-23
@@ -11,6 +11,7 @@ const minify = args.includes("--minify");
|
|||||||
const types = args.includes("--types");
|
const types = args.includes("--types");
|
||||||
const sourcemap = args.includes("--sourcemap");
|
const sourcemap = args.includes("--sourcemap");
|
||||||
const clean = args.includes("--clean");
|
const clean = args.includes("--clean");
|
||||||
|
const dev = args.includes("--dev");
|
||||||
|
|
||||||
// silence tsdown
|
// silence tsdown
|
||||||
const oldConsole = {
|
const oldConsole = {
|
||||||
@@ -55,7 +56,7 @@ async function buildTypes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let watcher_timeout: any;
|
let watcher_timeout: any;
|
||||||
function delayTypes() {
|
function delayTypes(delayTime = 1000) {
|
||||||
if (!watch || !types) return;
|
if (!watch || !types) return;
|
||||||
if (watcher_timeout) {
|
if (watcher_timeout) {
|
||||||
clearTimeout(watcher_timeout);
|
clearTimeout(watcher_timeout);
|
||||||
@@ -64,7 +65,7 @@ function delayTypes() {
|
|||||||
void buildTypes().catch((error) => {
|
void buildTypes().catch((error) => {
|
||||||
oldConsole.warn(c.cyan("[Types]"), c.red("build failed"), error);
|
oldConsole.warn(c.cyan("[Types]"), c.red("build failed"), error);
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, delayTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
const dependencies = Object.keys(pkg.dependencies);
|
const dependencies = Object.keys(pkg.dependencies);
|
||||||
@@ -87,18 +88,18 @@ const neverBundle = [
|
|||||||
*/
|
*/
|
||||||
async function buildApi() {
|
async function buildApi() {
|
||||||
await build({
|
await build({
|
||||||
|
|
||||||
minify,
|
minify,
|
||||||
sourcemap,
|
sourcemap,
|
||||||
// don't use tsdown's broken watch, we'll handle it ourselves
|
// don't use tsdown's broken watch, we'll handle it ourselves
|
||||||
watch: false,
|
watch: false,
|
||||||
|
dts: false,
|
||||||
define,
|
define,
|
||||||
entry: [
|
entry: [
|
||||||
"src/index.ts",
|
"src/index.ts",
|
||||||
"src/core/utils/index.ts",
|
"src/core/utils/index.ts",
|
||||||
// "src/plugins/index.ts",
|
|
||||||
"src/modes/index.ts",
|
"src/modes/index.ts",
|
||||||
],
|
],
|
||||||
|
unbundle: false,
|
||||||
outDir: "dist",
|
outDir: "dist",
|
||||||
deps: {
|
deps: {
|
||||||
neverBundle: [...neverBundle],
|
neverBundle: [...neverBundle],
|
||||||
@@ -109,8 +110,6 @@ async function buildApi() {
|
|||||||
nodeProtocol: true,
|
nodeProtocol: true,
|
||||||
format: ["esm"],
|
format: ["esm"],
|
||||||
|
|
||||||
// plugins: [dtsPlugin],
|
|
||||||
|
|
||||||
loader: {
|
loader: {
|
||||||
".svg": "dataurl",
|
".svg": "dataurl",
|
||||||
},
|
},
|
||||||
@@ -134,6 +133,7 @@ async function buildUi() {
|
|||||||
minify,
|
minify,
|
||||||
sourcemap,
|
sourcemap,
|
||||||
watch: false,
|
watch: false,
|
||||||
|
dts: false,
|
||||||
define,
|
define,
|
||||||
deps: {
|
deps: {
|
||||||
neverBundle: [
|
neverBundle: [
|
||||||
@@ -148,20 +148,22 @@ async function buildUi() {
|
|||||||
"@mantine/core",
|
"@mantine/core",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
devtools: false, // TODO: set true once tsdown's devtools performance is addressed
|
devtools: dev,
|
||||||
platform: "browser",
|
platform: "browser",
|
||||||
format: ["esm"],
|
format: ["esm"],
|
||||||
bundle: true,
|
unbundle: false,
|
||||||
treeshake: true,
|
treeshake: true,
|
||||||
loader: {
|
loader: {
|
||||||
".svg": "dataurl",
|
".svg": "dataurl",
|
||||||
},
|
},
|
||||||
logLevel: "silent",
|
|
||||||
|
|
||||||
// plugins: [dtsPlugin],
|
logLevel: "silent",
|
||||||
} satisfies UserConfig;
|
} satisfies UserConfig;
|
||||||
|
|
||||||
await build({
|
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
build({
|
||||||
...base,
|
...base,
|
||||||
entry: ["src/ui/index.ts", "src/ui/main.css", "src/ui/styles.css"],
|
entry: ["src/ui/index.ts", "src/ui/main.css", "src/ui/styles.css"],
|
||||||
outDir: "dist/ui",
|
outDir: "dist/ui",
|
||||||
@@ -170,9 +172,9 @@ async function buildUi() {
|
|||||||
delayTypes();
|
delayTypes();
|
||||||
oldConsole.log(c.cyan("[UI]"), c.green("built"));
|
oldConsole.log(c.cyan("[UI]"), c.green("built"));
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
|
||||||
await build({
|
build({
|
||||||
...base,
|
...base,
|
||||||
entry: ["src/ui/client/index.ts"],
|
entry: ["src/ui/client/index.ts"],
|
||||||
outDir: "dist/ui/client",
|
outDir: "dist/ui/client",
|
||||||
@@ -181,7 +183,8 @@ async function buildUi() {
|
|||||||
delayTypes();
|
delayTypes();
|
||||||
oldConsole.log(c.cyan("[UI]"), "Client", c.green("built"));
|
oldConsole.log(c.cyan("[UI]"), "Client", c.green("built"));
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -194,6 +197,7 @@ async function buildUiElements() {
|
|||||||
minify,
|
minify,
|
||||||
sourcemap,
|
sourcemap,
|
||||||
watch: false,
|
watch: false,
|
||||||
|
dts: false,
|
||||||
define,
|
define,
|
||||||
entry: ["src/ui/elements/index.ts"],
|
entry: ["src/ui/elements/index.ts"],
|
||||||
outDir: "dist/ui/elements",
|
outDir: "dist/ui/elements",
|
||||||
@@ -210,7 +214,6 @@ async function buildUiElements() {
|
|||||||
"use-sync-external-store",
|
"use-sync-external-store",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
// plugins: [dtsPlugin],
|
|
||||||
platform: "browser",
|
platform: "browser",
|
||||||
format: ["esm"],
|
format: ["esm"],
|
||||||
bundle: true,
|
bundle: true,
|
||||||
@@ -239,13 +242,13 @@ function baseConfig(adapter: string, overrides: Partial<UserConfig> = {}): UserC
|
|||||||
minify,
|
minify,
|
||||||
sourcemap,
|
sourcemap,
|
||||||
watch: false,
|
watch: false,
|
||||||
|
dts: false,
|
||||||
entry: [`src/adapter/${adapter}/index.ts`],
|
entry: [`src/adapter/${adapter}/index.ts`],
|
||||||
format: ["esm"],
|
format: ["esm"],
|
||||||
platform: "neutral",
|
platform: "neutral",
|
||||||
outDir: `dist/adapter/${adapter}`,
|
outDir: `dist/adapter/${adapter}`,
|
||||||
devtools: false, // TODO: set true once tsdown's devtools performance is addressed
|
devtools: dev,
|
||||||
nodeProtocol: true,
|
nodeProtocol: true,
|
||||||
// plugins: [dtsPlugin],
|
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
delayTypes();
|
delayTypes();
|
||||||
oldConsole.log(c.cyan("[Adapter]"), adapter || "base", c.green("built"));
|
oldConsole.log(c.cyan("[Adapter]"), adapter || "base", c.green("built"));
|
||||||
@@ -279,9 +282,10 @@ async function buildAdapters() {
|
|||||||
outDir: "dist/adapter",
|
outDir: "dist/adapter",
|
||||||
// only way to keep @vite-ignore comments
|
// only way to keep @vite-ignore comments
|
||||||
minify: false,
|
minify: false,
|
||||||
|
dts: false,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// specific adatpers
|
// specific adapters
|
||||||
build(baseConfig("react-router")),
|
build(baseConfig("react-router")),
|
||||||
build(
|
build(
|
||||||
baseConfig("browser", {
|
baseConfig("browser", {
|
||||||
@@ -375,18 +379,22 @@ async function buildAdapters() {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildAll() {
|
const buildPipeline = [buildApi, buildUi, buildUiElements, buildAdapters];
|
||||||
await Promise.all([buildApi(), buildUi(), buildUiElements(), buildAdapters()]);
|
|
||||||
|
// Run type generation in parallel, since it can be slow and doesn't block the main build
|
||||||
|
if (types) {
|
||||||
|
buildPipeline.push(async () => await buildTypes());
|
||||||
}
|
}
|
||||||
|
|
||||||
// initial build
|
// initial build
|
||||||
await buildAll();
|
await buildAll();
|
||||||
|
|
||||||
if (types) {
|
async function buildAll() {
|
||||||
await buildTypes();
|
await Promise.all(buildPipeline.map(fn => fn()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom watcher since tsdown's watch is broken in 8.3.5+
|
|
||||||
|
// custom watcher since tsdown's watch is broken in v0.21.7
|
||||||
if (watch) {
|
if (watch) {
|
||||||
oldConsole.log(c.cyan("[Watch]"), "watching for changes in src/...");
|
oldConsole.log(c.cyan("[Watch]"), "watching for changes in src/...");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user