@theholocron/vite-config 6.1.1 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/get-package-name-D6LP2hiw.js +12 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/presets/library.d.ts +15 -0
- package/dist/presets/library.js +44 -0
- package/dist/presets/node-app.d.ts +13 -0
- package/dist/presets/node-app.js +34 -0
- package/dist/presets/react-app.d.ts +11 -0
- package/dist/presets/react-app.js +27 -0
- package/package.json +39 -12
- package/index.js +0 -3
- package/presets/get-package-name.js +0 -14
- package/presets/library.js +0 -60
- package/presets/node-app.js +0 -47
- package/presets/react-app.js +0 -39
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
//#region presets/get-package-name.ts
|
|
4
|
+
function getPackageName() {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(readFileSync(resolve(process.cwd(), "package.json"), "utf-8")).name ?? "unknown";
|
|
7
|
+
} catch {
|
|
8
|
+
return "unknown";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getPackageName as t };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { UserConfig } from "vite";
|
|
2
|
+
//#region presets/library.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Vite preset for publishable libraries.
|
|
5
|
+
* Outputs ESM only; externalises React and react-dom by default.
|
|
6
|
+
* Uploads bundle stats to Codecov when CODECOV_TOKEN is set.
|
|
7
|
+
*/
|
|
8
|
+
declare function library({ entry, name, external, overrides }?: {
|
|
9
|
+
entry?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
external?: string[];
|
|
12
|
+
overrides?: UserConfig;
|
|
13
|
+
}): Promise<UserConfig>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { library };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { t as getPackageName } from "../get-package-name-D6LP2hiw.js";
|
|
2
|
+
import { mergeConfig } from "vite";
|
|
3
|
+
//#region presets/library.ts
|
|
4
|
+
/**
|
|
5
|
+
* Vite preset for publishable libraries.
|
|
6
|
+
* Outputs ESM only; externalises React and react-dom by default.
|
|
7
|
+
* Uploads bundle stats to Codecov when CODECOV_TOKEN is set.
|
|
8
|
+
*/
|
|
9
|
+
async function library({ entry = "src/index.ts", name, external = [], overrides = {} } = {}) {
|
|
10
|
+
const plugins = [];
|
|
11
|
+
try {
|
|
12
|
+
const { codecovVitePlugin } = await import("@codecov/vite-plugin");
|
|
13
|
+
plugins.push(codecovVitePlugin({
|
|
14
|
+
enableBundleAnalysis: !!process.env.CODECOV_TOKEN,
|
|
15
|
+
bundleName: getPackageName(),
|
|
16
|
+
uploadToken: process.env.CODECOV_TOKEN
|
|
17
|
+
}));
|
|
18
|
+
} catch {}
|
|
19
|
+
return mergeConfig({
|
|
20
|
+
plugins,
|
|
21
|
+
build: {
|
|
22
|
+
lib: {
|
|
23
|
+
entry,
|
|
24
|
+
name,
|
|
25
|
+
formats: ["es"],
|
|
26
|
+
fileName: () => "index.mjs"
|
|
27
|
+
},
|
|
28
|
+
rollupOptions: {
|
|
29
|
+
external: [
|
|
30
|
+
"react",
|
|
31
|
+
"react-dom",
|
|
32
|
+
...external
|
|
33
|
+
],
|
|
34
|
+
output: { globals: {
|
|
35
|
+
react: "React",
|
|
36
|
+
"react-dom": "ReactDOM"
|
|
37
|
+
} }
|
|
38
|
+
},
|
|
39
|
+
sourcemap: true
|
|
40
|
+
}
|
|
41
|
+
}, overrides);
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { library };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UserConfig } from "vite";
|
|
2
|
+
//#region presets/node-app.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Vite preset for Node.js CLI tools and server apps.
|
|
5
|
+
* Targets Node 22, outputs a single ESM bundle, no browser polyfills.
|
|
6
|
+
* Uploads bundle stats to Codecov when CODECOV_TOKEN is set.
|
|
7
|
+
*/
|
|
8
|
+
declare function nodeApp({ entry, overrides }?: {
|
|
9
|
+
entry?: string;
|
|
10
|
+
overrides?: UserConfig;
|
|
11
|
+
}): Promise<UserConfig>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { nodeApp };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { t as getPackageName } from "../get-package-name-D6LP2hiw.js";
|
|
2
|
+
import { mergeConfig } from "vite";
|
|
3
|
+
//#region presets/node-app.ts
|
|
4
|
+
/**
|
|
5
|
+
* Vite preset for Node.js CLI tools and server apps.
|
|
6
|
+
* Targets Node 22, outputs a single ESM bundle, no browser polyfills.
|
|
7
|
+
* Uploads bundle stats to Codecov when CODECOV_TOKEN is set.
|
|
8
|
+
*/
|
|
9
|
+
async function nodeApp({ entry = "src/index.ts", overrides = {} } = {}) {
|
|
10
|
+
const plugins = [];
|
|
11
|
+
try {
|
|
12
|
+
const { codecovVitePlugin } = await import("@codecov/vite-plugin");
|
|
13
|
+
plugins.push(codecovVitePlugin({
|
|
14
|
+
enableBundleAnalysis: !!process.env.CODECOV_TOKEN,
|
|
15
|
+
bundleName: getPackageName(),
|
|
16
|
+
uploadToken: process.env.CODECOV_TOKEN
|
|
17
|
+
}));
|
|
18
|
+
} catch {}
|
|
19
|
+
return mergeConfig({
|
|
20
|
+
plugins,
|
|
21
|
+
build: {
|
|
22
|
+
target: "node22",
|
|
23
|
+
lib: {
|
|
24
|
+
entry,
|
|
25
|
+
formats: ["es"],
|
|
26
|
+
fileName: () => "index.mjs"
|
|
27
|
+
},
|
|
28
|
+
sourcemap: true,
|
|
29
|
+
rollupOptions: { external: [/^node:/] }
|
|
30
|
+
}
|
|
31
|
+
}, overrides);
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { nodeApp };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UserConfig } from "vite";
|
|
2
|
+
//#region presets/react-app.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Vite preset for React single-page applications.
|
|
5
|
+
* Wires up @vitejs/plugin-react; accepts a vite-tsconfig-paths instance
|
|
6
|
+
* via options.plugins if tsconfig path aliases are needed.
|
|
7
|
+
* Uploads bundle stats to Codecov when CODECOV_TOKEN is set.
|
|
8
|
+
*/
|
|
9
|
+
declare function reactApp(overrides?: UserConfig): Promise<UserConfig>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { reactApp };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { t as getPackageName } from "../get-package-name-D6LP2hiw.js";
|
|
2
|
+
import { mergeConfig } from "vite";
|
|
3
|
+
//#region presets/react-app.ts
|
|
4
|
+
/**
|
|
5
|
+
* Vite preset for React single-page applications.
|
|
6
|
+
* Wires up @vitejs/plugin-react; accepts a vite-tsconfig-paths instance
|
|
7
|
+
* via options.plugins if tsconfig path aliases are needed.
|
|
8
|
+
* Uploads bundle stats to Codecov when CODECOV_TOKEN is set.
|
|
9
|
+
*/
|
|
10
|
+
async function reactApp(overrides = {}) {
|
|
11
|
+
const { default: react } = await import("@vitejs/plugin-react");
|
|
12
|
+
const plugins = [react()];
|
|
13
|
+
try {
|
|
14
|
+
const { codecovVitePlugin } = await import("@codecov/vite-plugin");
|
|
15
|
+
plugins.push(codecovVitePlugin({
|
|
16
|
+
enableBundleAnalysis: !!process.env.CODECOV_TOKEN,
|
|
17
|
+
bundleName: getPackageName(),
|
|
18
|
+
uploadToken: process.env.CODECOV_TOKEN
|
|
19
|
+
}));
|
|
20
|
+
} catch {}
|
|
21
|
+
return mergeConfig({
|
|
22
|
+
plugins,
|
|
23
|
+
build: { sourcemap: true }
|
|
24
|
+
}, overrides);
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { reactApp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/vite-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Vite configuration presets for libraries, React apps, and Node tools within the Galaxy.",
|
|
5
5
|
"homepage": "https://github.com/theholocron/configs/tree/main/packages/vite-config#readme",
|
|
6
6
|
"bugs": "https://github.com/theholocron/configs/issues",
|
|
@@ -10,29 +10,48 @@
|
|
|
10
10
|
},
|
|
11
11
|
"license": "GPL-3.0",
|
|
12
12
|
"author": "Newton Koumantzelis",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"vite",
|
|
15
|
+
"bundler",
|
|
16
|
+
"react",
|
|
17
|
+
"build",
|
|
18
|
+
"config",
|
|
19
|
+
"theholocron"
|
|
20
|
+
],
|
|
13
21
|
"type": "module",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"tsdown": "^0.22.8",
|
|
24
|
+
"typescript": "^5.9.3",
|
|
25
|
+
"vitest": "^4.0.0",
|
|
26
|
+
"vite": "^6.0.0",
|
|
27
|
+
"@theholocron/tsconfig": "7.1.0",
|
|
28
|
+
"@theholocron/vitest-config": "7.1.0"
|
|
29
|
+
},
|
|
14
30
|
"exports": {
|
|
15
31
|
".": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"default": "./dist/index.js"
|
|
18
35
|
},
|
|
19
36
|
"./library": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
37
|
+
"types": "./dist/presets/library.d.ts",
|
|
38
|
+
"import": "./dist/presets/library.js",
|
|
39
|
+
"default": "./dist/presets/library.js"
|
|
22
40
|
},
|
|
23
41
|
"./react-app": {
|
|
24
|
-
"
|
|
25
|
-
"
|
|
42
|
+
"types": "./dist/presets/react-app.d.ts",
|
|
43
|
+
"import": "./dist/presets/react-app.js",
|
|
44
|
+
"default": "./dist/presets/react-app.js"
|
|
26
45
|
},
|
|
27
46
|
"./node-app": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
47
|
+
"types": "./dist/presets/node-app.d.ts",
|
|
48
|
+
"import": "./dist/presets/node-app.js",
|
|
49
|
+
"default": "./dist/presets/node-app.js"
|
|
30
50
|
},
|
|
31
51
|
"./package.json": "./package.json"
|
|
32
52
|
},
|
|
33
53
|
"files": [
|
|
34
|
-
"
|
|
35
|
-
"presets/"
|
|
54
|
+
"dist/"
|
|
36
55
|
],
|
|
37
56
|
"peerDependencies": {
|
|
38
57
|
"vite": "^6",
|
|
@@ -51,9 +70,17 @@
|
|
|
51
70
|
"optional": true
|
|
52
71
|
}
|
|
53
72
|
},
|
|
73
|
+
"engines": {
|
|
74
|
+
"node": ">=22.0.0"
|
|
75
|
+
},
|
|
54
76
|
"publishConfig": {
|
|
55
77
|
"access": "public"
|
|
56
78
|
},
|
|
57
79
|
"releases": "https://github.com/theholocron/configs/releases",
|
|
58
|
-
"wiki": "https://github.com/theholocron/configs/wiki"
|
|
80
|
+
"wiki": "https://github.com/theholocron/configs/wiki",
|
|
81
|
+
"scripts": {
|
|
82
|
+
"build": "tsdown",
|
|
83
|
+
"typecheck": "tsc --noEmit",
|
|
84
|
+
"test": "vitest run"
|
|
85
|
+
}
|
|
59
86
|
}
|
package/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { resolve } from "node:path";
|
|
3
|
-
|
|
4
|
-
export function getPackageName() {
|
|
5
|
-
try {
|
|
6
|
-
return (
|
|
7
|
-
JSON.parse(
|
|
8
|
-
readFileSync(resolve(process.cwd(), "package.json"), "utf-8"),
|
|
9
|
-
).name ?? "unknown"
|
|
10
|
-
);
|
|
11
|
-
} catch {
|
|
12
|
-
return "unknown";
|
|
13
|
-
}
|
|
14
|
-
}
|
package/presets/library.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { mergeConfig } from "vite";
|
|
2
|
-
import { getPackageName } from "./get-package-name.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Vite preset for publishable libraries.
|
|
6
|
-
* Outputs ESM only; externalises React and react-dom by default.
|
|
7
|
-
* Uploads bundle stats to Codecov when CODECOV_TOKEN is set.
|
|
8
|
-
*
|
|
9
|
-
* @param {object} options
|
|
10
|
-
* @param {string} [options.entry='src/index.ts'] Library entry point
|
|
11
|
-
* @param {string} [options.name] UMD global name (required for UMD builds)
|
|
12
|
-
* @param {string[]} [options.external=[]] Additional peer deps to externalise
|
|
13
|
-
* @param {import('vite').UserConfig} [options.overrides={}] Merged last
|
|
14
|
-
* @returns {Promise<import('vite').UserConfig>}
|
|
15
|
-
*/
|
|
16
|
-
export async function library({
|
|
17
|
-
entry = "src/index.ts",
|
|
18
|
-
name,
|
|
19
|
-
external = [],
|
|
20
|
-
overrides = {},
|
|
21
|
-
} = {}) {
|
|
22
|
-
const plugins = [];
|
|
23
|
-
try {
|
|
24
|
-
const { codecovVitePlugin } = await import("@codecov/vite-plugin");
|
|
25
|
-
plugins.push(
|
|
26
|
-
codecovVitePlugin({
|
|
27
|
-
enableBundleAnalysis: !!process.env.CODECOV_TOKEN,
|
|
28
|
-
bundleName: getPackageName(),
|
|
29
|
-
uploadToken: process.env.CODECOV_TOKEN,
|
|
30
|
-
}),
|
|
31
|
-
);
|
|
32
|
-
} catch {
|
|
33
|
-
// @codecov/vite-plugin not installed — bundle analysis skipped
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return mergeConfig(
|
|
37
|
-
{
|
|
38
|
-
plugins,
|
|
39
|
-
build: {
|
|
40
|
-
lib: {
|
|
41
|
-
entry,
|
|
42
|
-
name,
|
|
43
|
-
formats: ["es"],
|
|
44
|
-
fileName: () => "index.mjs",
|
|
45
|
-
},
|
|
46
|
-
rollupOptions: {
|
|
47
|
-
external: ["react", "react-dom", ...external],
|
|
48
|
-
output: {
|
|
49
|
-
globals: {
|
|
50
|
-
react: "React",
|
|
51
|
-
"react-dom": "ReactDOM",
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
sourcemap: true,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
overrides,
|
|
59
|
-
);
|
|
60
|
-
}
|
package/presets/node-app.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { mergeConfig } from "vite";
|
|
2
|
-
import { getPackageName } from "./get-package-name.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Vite preset for Node.js CLI tools and server apps.
|
|
6
|
-
* Targets Node 22, outputs a single ESM bundle, no browser polyfills.
|
|
7
|
-
* Uploads bundle stats to Codecov when CODECOV_TOKEN is set.
|
|
8
|
-
*
|
|
9
|
-
* @param {object} options
|
|
10
|
-
* @param {string} [options.entry='src/index.ts'] Application entry point
|
|
11
|
-
* @param {import('vite').UserConfig} [options.overrides={}] Merged last
|
|
12
|
-
* @returns {Promise<import('vite').UserConfig>}
|
|
13
|
-
*/
|
|
14
|
-
export async function nodeApp({ entry = "src/index.ts", overrides = {} } = {}) {
|
|
15
|
-
const plugins = [];
|
|
16
|
-
try {
|
|
17
|
-
const { codecovVitePlugin } = await import("@codecov/vite-plugin");
|
|
18
|
-
plugins.push(
|
|
19
|
-
codecovVitePlugin({
|
|
20
|
-
enableBundleAnalysis: !!process.env.CODECOV_TOKEN,
|
|
21
|
-
bundleName: getPackageName(),
|
|
22
|
-
uploadToken: process.env.CODECOV_TOKEN,
|
|
23
|
-
}),
|
|
24
|
-
);
|
|
25
|
-
} catch {
|
|
26
|
-
// @codecov/vite-plugin not installed — bundle analysis skipped
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return mergeConfig(
|
|
30
|
-
{
|
|
31
|
-
plugins,
|
|
32
|
-
build: {
|
|
33
|
-
target: "node22",
|
|
34
|
-
lib: {
|
|
35
|
-
entry,
|
|
36
|
-
formats: ["es"],
|
|
37
|
-
fileName: () => "index.mjs",
|
|
38
|
-
},
|
|
39
|
-
sourcemap: true,
|
|
40
|
-
rollupOptions: {
|
|
41
|
-
external: [/^node:/],
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
overrides,
|
|
46
|
-
);
|
|
47
|
-
}
|
package/presets/react-app.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { mergeConfig } from "vite";
|
|
2
|
-
import { getPackageName } from "./get-package-name.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Vite preset for React single-page applications.
|
|
6
|
-
* Wires up @vitejs/plugin-react; accepts a vite-tsconfig-paths instance
|
|
7
|
-
* via options.plugins if tsconfig path aliases are needed.
|
|
8
|
-
* Uploads bundle stats to Codecov when CODECOV_TOKEN is set.
|
|
9
|
-
*
|
|
10
|
-
* @param {import('vite').UserConfig} [overrides={}]
|
|
11
|
-
* @returns {Promise<import('vite').UserConfig>}
|
|
12
|
-
*/
|
|
13
|
-
export async function reactApp(overrides = {}) {
|
|
14
|
-
const { default: react } = await import("@vitejs/plugin-react");
|
|
15
|
-
|
|
16
|
-
const plugins = [react()];
|
|
17
|
-
try {
|
|
18
|
-
const { codecovVitePlugin } = await import("@codecov/vite-plugin");
|
|
19
|
-
plugins.push(
|
|
20
|
-
codecovVitePlugin({
|
|
21
|
-
enableBundleAnalysis: !!process.env.CODECOV_TOKEN,
|
|
22
|
-
bundleName: getPackageName(),
|
|
23
|
-
uploadToken: process.env.CODECOV_TOKEN,
|
|
24
|
-
}),
|
|
25
|
-
);
|
|
26
|
-
} catch {
|
|
27
|
-
// @codecov/vite-plugin not installed — bundle analysis skipped
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return mergeConfig(
|
|
31
|
-
{
|
|
32
|
-
plugins,
|
|
33
|
-
build: {
|
|
34
|
-
sourcemap: true,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
overrides,
|
|
38
|
-
);
|
|
39
|
-
}
|