Skip to content

Commit 7204ec8

Browse files
author
Mike Valeriano
committed
chore: modularize vite config
1 parent 39a6feb commit 7204ec8

13 files changed

Lines changed: 120 additions & 98 deletions

.vite/build.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { BuildEnvironmentOptions } from "vite";
2+
3+
export function getBuild(entryFiles: string[]): BuildEnvironmentOptions {
4+
return {
5+
target: "esnext",
6+
lib: {
7+
entry: entryFiles,
8+
formats: ["es"],
9+
fileName: (_, entryName) => `${entryName}.js`,
10+
},
11+
outDir: "./build",
12+
emptyOutDir: true,
13+
rollupOptions: {
14+
output: {
15+
preserveModules: true,
16+
preserveModulesRoot: "src",
17+
// this outputs bundled/internal packages to a directory named _internal
18+
entryFileNames: ({ name }) => `${name.replace("node_modules/", "_internal/")}.js`,
19+
},
20+
},
21+
minify: "terser",
22+
terserOptions: {
23+
compress: false,
24+
format: {
25+
comments: false,
26+
},
27+
},
28+
};
29+
}

.vite/entries.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { glob } from "node:fs/promises";
2+
3+
export async function getEntryFiles(): Promise<string[]> {
4+
const entryFiles: string[] = [];
5+
for await (const file of glob("src/**/*.ts")) {
6+
if (!(file.endsWith(".test.ts") || file.endsWith(".spec.ts"))) {
7+
entryFiles.push(file);
8+
}
9+
}
10+
11+
return entryFiles;
12+
}

.vite/optimize.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { DepOptimizationOptions } from "vite";
2+
3+
export function getOptimize(): DepOptimizationOptions {
4+
return {
5+
esbuildOptions: {
6+
target: "esnext",
7+
format: "esm",
8+
},
9+
};
10+
}

.vite/plugins.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import nodeExternals from "rollup-plugin-node-externals";
2+
import type { PluginOption } from "vite";
3+
import tsconfigPaths from "vite-tsconfig-paths";
4+
5+
export function getPlugins(): PluginOption[] {
6+
return [
7+
// externalize node builtins and configure dependencies to be externalized (or not)
8+
nodeExternals({
9+
// externalize dependencies in package.json
10+
deps: true,
11+
// devDependencies in package.json
12+
devDeps: false,
13+
// dependencies to be bundled
14+
exclude: ["@mkvlrn/result"],
15+
}),
16+
// resolve tsconfig path aliases
17+
tsconfigPaths(),
18+
];
19+
}

biome.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
{
6767
// test files, config files, and some scripts
6868
// export defaults from them, and also import from node
69-
"includes": ["**/*.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/scripts/**"],
69+
"includes": ["**/*.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/.vite/**"],
7070
"linter": {
7171
"rules": {
7272
"correctness": {

package-lock.json

Lines changed: 36 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"prepare": "husky"
3131
},
3232
"devDependencies": {
33-
"@biomejs/biome": "^2.0.0",
33+
"@biomejs/biome": "^2.0.4",
3434
"@commitlint/cli": "^19.8.1",
3535
"@commitlint/config-conventional": "^19.8.1",
3636
"@types/node": "^24.0.3",

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** biome-ignore-all lint/suspicious/noConsole: needed, yo */
22

3-
import { divide } from "~/lib/advanced-math.ts";
4-
import { add } from "~/lib/basic-math.ts";
3+
import { divide } from "~/math/advanced-math.ts";
4+
import { add } from "~/math/basic-math.ts";
55

66
function main(): void {
77
const sum = add(1, 2);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "node:assert/strict";
22
import { describe, it } from "node:test";
3-
import { divide, multiply } from "~/lib/advanced-math.ts";
3+
import { divide, multiply } from "~/math/advanced-math.ts";
44

55
describe("advanced-math", () => {
66
describe("multiply", () => {

0 commit comments

Comments
 (0)