@theholocron/vite-config 5.0.0 → 5.1.1

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/README.md CHANGED
@@ -14,15 +14,13 @@ Pick the preset that matches your project type. All presets accept an `overrides
14
14
 
15
15
  ### Publishable library
16
16
 
17
- Outputs ESM only; externalises `react` and `react-dom` by default.
17
+ Outputs ESM only; externalises `react` and `react-dom` by default. Returns a `Promise` because the plugin is loaded dynamically.
18
18
 
19
19
  ```javascript
20
20
  import { defineConfig } from "vite";
21
21
  import { library } from "@theholocron/vite-config/library";
22
22
 
23
- export default defineConfig(
24
- library({ entry: "src/index.ts", name: "MyLib" })
25
- );
23
+ export default defineConfig(await library({ entry: "src/index.ts", name: "MyLib" }));
26
24
  ```
27
25
 
28
26
  ### React single-page application
@@ -48,11 +46,11 @@ export default defineConfig(await reactApp({ plugins: [tsconfigPaths()] }));
48
46
 
49
47
  ### Node.js CLI tool or server app
50
48
 
51
- Targets Node 22; outputs a single ESM bundle with no browser polyfills.
49
+ Targets Node 22; outputs a single ESM bundle with no browser polyfills. Returns a `Promise` because the plugin is loaded dynamically.
52
50
 
53
51
  ```javascript
54
52
  import { defineConfig } from "vite";
55
53
  import { nodeApp } from "@theholocron/vite-config/node-app";
56
54
 
57
- export default defineConfig(nodeApp({ entry: "src/index.ts" }));
55
+ export default defineConfig(await nodeApp({ entry: "src/index.ts" }));
58
56
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/vite-config",
3
- "version": "5.0.0",
3
+ "version": "5.1.1",
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",
@@ -36,10 +36,14 @@
36
36
  ],
37
37
  "peerDependencies": {
38
38
  "vite": "^6",
39
+ "@codecov/vite-plugin": "^2",
39
40
  "@vitejs/plugin-react": "^4",
40
41
  "vite-tsconfig-paths": "^5"
41
42
  },
42
43
  "peerDependenciesMeta": {
44
+ "@codecov/vite-plugin": {
45
+ "optional": true
46
+ },
43
47
  "@vitejs/plugin-react": {
44
48
  "optional": true
45
49
  },
@@ -0,0 +1,10 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+
4
+ export 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
+ }
@@ -1,19 +1,36 @@
1
1
  import { mergeConfig } from "vite";
2
+ import { getPackageName } from "./get-package-name.js";
2
3
 
3
4
  /**
4
5
  * Vite preset for publishable libraries.
5
6
  * Outputs ESM only; externalises React and react-dom by default.
7
+ * Uploads bundle stats to Codecov when CODECOV_TOKEN is set.
6
8
  *
7
9
  * @param {object} options
8
10
  * @param {string} [options.entry='src/index.ts'] Library entry point
9
11
  * @param {string} [options.name] UMD global name (required for UMD builds)
10
12
  * @param {string[]} [options.external=[]] Additional peer deps to externalise
11
13
  * @param {import('vite').UserConfig} [options.overrides={}] Merged last
12
- * @returns {import('vite').UserConfig}
14
+ * @returns {Promise<import('vite').UserConfig>}
13
15
  */
14
- export function library({ entry = "src/index.ts", name, external = [], overrides = {} } = {}) {
16
+ export async function library({ entry = "src/index.ts", name, external = [], overrides = {} } = {}) {
17
+ const plugins = [];
18
+ try {
19
+ const { codecovVitePlugin } = await import("@codecov/vite-plugin");
20
+ plugins.push(
21
+ codecovVitePlugin({
22
+ enableBundleAnalysis: !!process.env.CODECOV_TOKEN,
23
+ bundleName: getPackageName(),
24
+ uploadToken: process.env.CODECOV_TOKEN,
25
+ }),
26
+ );
27
+ } catch {
28
+ // @codecov/vite-plugin not installed — bundle analysis skipped
29
+ }
30
+
15
31
  return mergeConfig(
16
32
  {
33
+ plugins,
17
34
  build: {
18
35
  lib: {
19
36
  entry,
@@ -1,17 +1,34 @@
1
1
  import { mergeConfig } from "vite";
2
+ import { getPackageName } from "./get-package-name.js";
2
3
 
3
4
  /**
4
5
  * Vite preset for Node.js CLI tools and server apps.
5
6
  * Targets Node 22, outputs a single ESM bundle, no browser polyfills.
7
+ * Uploads bundle stats to Codecov when CODECOV_TOKEN is set.
6
8
  *
7
9
  * @param {object} options
8
10
  * @param {string} [options.entry='src/index.ts'] Application entry point
9
11
  * @param {import('vite').UserConfig} [options.overrides={}] Merged last
10
- * @returns {import('vite').UserConfig}
12
+ * @returns {Promise<import('vite').UserConfig>}
11
13
  */
12
- export function nodeApp({ entry = "src/index.ts", overrides = {} } = {}) {
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
+
13
29
  return mergeConfig(
14
30
  {
31
+ plugins,
15
32
  build: {
16
33
  target: "node22",
17
34
  lib: {
@@ -1,9 +1,11 @@
1
1
  import { mergeConfig } from "vite";
2
+ import { getPackageName } from "./get-package-name.js";
2
3
 
3
4
  /**
4
5
  * Vite preset for React single-page applications.
5
6
  * Wires up @vitejs/plugin-react; accepts a vite-tsconfig-paths instance
6
7
  * via options.plugins if tsconfig path aliases are needed.
8
+ * Uploads bundle stats to Codecov when CODECOV_TOKEN is set.
7
9
  *
8
10
  * @param {import('vite').UserConfig} [overrides={}]
9
11
  * @returns {Promise<import('vite').UserConfig>}
@@ -11,9 +13,23 @@ import { mergeConfig } from "vite";
11
13
  export async function reactApp(overrides = {}) {
12
14
  const { default: react } = await import("@vitejs/plugin-react");
13
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
+
14
30
  return mergeConfig(
15
31
  {
16
- plugins: [react()],
32
+ plugins,
17
33
  build: {
18
34
  sourcemap: true,
19
35
  },