@codefluss/vite-config-lib 0.0.1-alpha.2 → 0.0.1-alpha.3
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.
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// vite.config.base.ts
|
|
31
|
+
var vite_config_base_exports = {};
|
|
32
|
+
__export(vite_config_base_exports, {
|
|
33
|
+
createLibraryConfig: () => createLibraryConfig
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(vite_config_base_exports);
|
|
36
|
+
var import_plugin_react = __toESM(require("@vitejs/plugin-react"), 1);
|
|
37
|
+
var import_vite_plugin_dts = __toESM(require("vite-plugin-dts"), 1);
|
|
38
|
+
var import_path = require("path");
|
|
39
|
+
function createLibraryConfig(options) {
|
|
40
|
+
const {
|
|
41
|
+
libraryName,
|
|
42
|
+
entry = "src/index.ts",
|
|
43
|
+
formats = ["es", "cjs"],
|
|
44
|
+
external = [],
|
|
45
|
+
globals = {},
|
|
46
|
+
sourcemap = true,
|
|
47
|
+
minify = "terser",
|
|
48
|
+
dts: dtsConfig = {},
|
|
49
|
+
plugins = [],
|
|
50
|
+
viteConfigOverrides = {}
|
|
51
|
+
} = options;
|
|
52
|
+
const standardExternals = [
|
|
53
|
+
"react",
|
|
54
|
+
"react-dom",
|
|
55
|
+
"react/jsx-runtime"
|
|
56
|
+
];
|
|
57
|
+
const allExternals = [.../* @__PURE__ */ new Set([...standardExternals, ...external])];
|
|
58
|
+
const standardGlobals = {
|
|
59
|
+
react: "React",
|
|
60
|
+
"react-dom": "ReactDOM",
|
|
61
|
+
...globals
|
|
62
|
+
};
|
|
63
|
+
const dtsPluginConfig = {
|
|
64
|
+
insertTypesEntry: true,
|
|
65
|
+
include: dtsConfig.include ?? ["src/**/*.ts", "src/**/*.tsx"],
|
|
66
|
+
exclude: dtsConfig.exclude ?? ["src/**/*.test.ts", "src/**/*.test.tsx"],
|
|
67
|
+
skipDiagnostics: dtsConfig.skipDiagnostics ?? false
|
|
68
|
+
};
|
|
69
|
+
const config = {
|
|
70
|
+
plugins: [
|
|
71
|
+
(0, import_plugin_react.default)(),
|
|
72
|
+
(0, import_vite_plugin_dts.default)(dtsPluginConfig),
|
|
73
|
+
...plugins
|
|
74
|
+
],
|
|
75
|
+
build: {
|
|
76
|
+
lib: {
|
|
77
|
+
entry: (0, import_path.resolve)(process.cwd(), entry),
|
|
78
|
+
name: libraryName,
|
|
79
|
+
formats,
|
|
80
|
+
fileName: (format) => {
|
|
81
|
+
if (format === "es") return "index.mjs";
|
|
82
|
+
if (format === "cjs") return "index.js";
|
|
83
|
+
return `index.${format}.js`;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
rollupOptions: {
|
|
87
|
+
external: allExternals,
|
|
88
|
+
output: {
|
|
89
|
+
globals: standardGlobals
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
sourcemap,
|
|
93
|
+
minify
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const mergedLib = {
|
|
97
|
+
...config.build?.lib,
|
|
98
|
+
...viteConfigOverrides.build?.lib
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
...config,
|
|
102
|
+
...viteConfigOverrides,
|
|
103
|
+
plugins: [...config.plugins ?? [], ...viteConfigOverrides.plugins ?? []],
|
|
104
|
+
build: {
|
|
105
|
+
...config.build,
|
|
106
|
+
...viteConfigOverrides.build,
|
|
107
|
+
lib: mergedLib.entry ? mergedLib : config.build?.lib,
|
|
108
|
+
rollupOptions: {
|
|
109
|
+
...config.build?.rollupOptions,
|
|
110
|
+
...viteConfigOverrides.build?.rollupOptions,
|
|
111
|
+
external: viteConfigOverrides.build?.rollupOptions?.external ?? allExternals,
|
|
112
|
+
output: {
|
|
113
|
+
...config.build?.rollupOptions?.output,
|
|
114
|
+
...viteConfigOverrides.build?.rollupOptions?.output
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
121
|
+
0 && (module.exports = {
|
|
122
|
+
createLibraryConfig
|
|
123
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { PluginOption, UserConfig } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for creating a library build with Vite
|
|
5
|
+
*/
|
|
6
|
+
interface LibraryConfigOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Library name for UMD/IIFE builds (e.g., 'PluginCanvas2D')
|
|
9
|
+
*/
|
|
10
|
+
libraryName: string;
|
|
11
|
+
/**
|
|
12
|
+
* Entry point relative to package root (default: 'src/index.ts')
|
|
13
|
+
*/
|
|
14
|
+
entry?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Output formats (default: ['es', 'cjs'])
|
|
17
|
+
* - 'es' for ESM (.mjs)
|
|
18
|
+
* - 'cjs' for CommonJS (.js)
|
|
19
|
+
*/
|
|
20
|
+
formats?: ('es' | 'cjs' | 'umd' | 'iife')[];
|
|
21
|
+
/**
|
|
22
|
+
* External dependencies to exclude from bundle
|
|
23
|
+
* Common React dependencies are automatically included
|
|
24
|
+
*/
|
|
25
|
+
external?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Additional global variable mappings for UMD/IIFE builds
|
|
28
|
+
*/
|
|
29
|
+
globals?: Record<string, string>;
|
|
30
|
+
/**
|
|
31
|
+
* Enable sourcemaps (default: true)
|
|
32
|
+
*/
|
|
33
|
+
sourcemap?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Enable minification with Terser (default: true)
|
|
36
|
+
*/
|
|
37
|
+
minify?: boolean | 'terser' | 'esbuild';
|
|
38
|
+
/**
|
|
39
|
+
* DTS plugin configuration
|
|
40
|
+
*/
|
|
41
|
+
dts?: {
|
|
42
|
+
/**
|
|
43
|
+
* Include patterns (default: ['src/**\/*.ts', 'src/**\/*.tsx'])
|
|
44
|
+
*/
|
|
45
|
+
include?: string[];
|
|
46
|
+
/**
|
|
47
|
+
* Exclude patterns (default: ['src/**\/*.test.ts', 'src/**\/*.test.tsx'])
|
|
48
|
+
*/
|
|
49
|
+
exclude?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Skip TypeScript diagnostics (useful for React 19 + R3F compatibility)
|
|
52
|
+
*/
|
|
53
|
+
skipDiagnostics?: boolean;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Additional Vite plugins
|
|
57
|
+
*/
|
|
58
|
+
plugins?: PluginOption[];
|
|
59
|
+
/**
|
|
60
|
+
* Override any Vite config option
|
|
61
|
+
*/
|
|
62
|
+
viteConfigOverrides?: Partial<UserConfig>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates a Vite configuration for library builds with sensible defaults
|
|
66
|
+
*
|
|
67
|
+
* Features:
|
|
68
|
+
* - React plugin with automatic JSX runtime
|
|
69
|
+
* - TypeScript declaration files with vite-plugin-dts
|
|
70
|
+
* - Dual format output (ESM + CJS) by default
|
|
71
|
+
* - React, React-DOM externalized automatically
|
|
72
|
+
* - Sourcemaps and minification enabled by default
|
|
73
|
+
* - Tree-shaking friendly builds
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // vite.config.ts
|
|
78
|
+
* import { createLibraryConfig } from '@codefluss/vite-config-lib';
|
|
79
|
+
*
|
|
80
|
+
* export default createLibraryConfig({
|
|
81
|
+
* libraryName: 'PluginCanvas2D',
|
|
82
|
+
* external: ['fabric', 'zustand'],
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function createLibraryConfig(options: LibraryConfigOptions): UserConfig;
|
|
87
|
+
|
|
88
|
+
export { type LibraryConfigOptions, createLibraryConfig };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PluginOption, UserConfig } from 'vite';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Configuration options for creating a library build with Vite
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
interface LibraryConfigOptions {
|
|
6
7
|
/**
|
|
7
8
|
* Library name for UMD/IIFE builds (e.g., 'PluginCanvas2D')
|
|
8
9
|
*/
|
|
@@ -82,5 +83,6 @@ export interface LibraryConfigOptions {
|
|
|
82
83
|
* });
|
|
83
84
|
* ```
|
|
84
85
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
declare function createLibraryConfig(options: LibraryConfigOptions): UserConfig;
|
|
87
|
+
|
|
88
|
+
export { type LibraryConfigOptions, createLibraryConfig };
|
package/dist/vite.config.base.js
CHANGED
|
@@ -1,104 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
...config,
|
|
87
|
-
...viteConfigOverrides,
|
|
88
|
-
plugins: [...(config.plugins ?? []), ...(viteConfigOverrides.plugins ?? [])],
|
|
89
|
-
build: {
|
|
90
|
-
...config.build,
|
|
91
|
-
...viteConfigOverrides.build,
|
|
92
|
-
lib: (mergedLib.entry ? mergedLib : config.build?.lib),
|
|
93
|
-
rollupOptions: {
|
|
94
|
-
...config.build?.rollupOptions,
|
|
95
|
-
...viteConfigOverrides.build?.rollupOptions,
|
|
96
|
-
external: viteConfigOverrides.build?.rollupOptions?.external ?? allExternals,
|
|
97
|
-
output: {
|
|
98
|
-
...config.build?.rollupOptions?.output,
|
|
99
|
-
...viteConfigOverrides.build?.rollupOptions?.output,
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
};
|
|
1
|
+
// vite.config.base.ts
|
|
2
|
+
import react from "@vitejs/plugin-react";
|
|
3
|
+
import dts from "vite-plugin-dts";
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
function createLibraryConfig(options) {
|
|
6
|
+
const {
|
|
7
|
+
libraryName,
|
|
8
|
+
entry = "src/index.ts",
|
|
9
|
+
formats = ["es", "cjs"],
|
|
10
|
+
external = [],
|
|
11
|
+
globals = {},
|
|
12
|
+
sourcemap = true,
|
|
13
|
+
minify = "terser",
|
|
14
|
+
dts: dtsConfig = {},
|
|
15
|
+
plugins = [],
|
|
16
|
+
viteConfigOverrides = {}
|
|
17
|
+
} = options;
|
|
18
|
+
const standardExternals = [
|
|
19
|
+
"react",
|
|
20
|
+
"react-dom",
|
|
21
|
+
"react/jsx-runtime"
|
|
22
|
+
];
|
|
23
|
+
const allExternals = [.../* @__PURE__ */ new Set([...standardExternals, ...external])];
|
|
24
|
+
const standardGlobals = {
|
|
25
|
+
react: "React",
|
|
26
|
+
"react-dom": "ReactDOM",
|
|
27
|
+
...globals
|
|
28
|
+
};
|
|
29
|
+
const dtsPluginConfig = {
|
|
30
|
+
insertTypesEntry: true,
|
|
31
|
+
include: dtsConfig.include ?? ["src/**/*.ts", "src/**/*.tsx"],
|
|
32
|
+
exclude: dtsConfig.exclude ?? ["src/**/*.test.ts", "src/**/*.test.tsx"],
|
|
33
|
+
skipDiagnostics: dtsConfig.skipDiagnostics ?? false
|
|
34
|
+
};
|
|
35
|
+
const config = {
|
|
36
|
+
plugins: [
|
|
37
|
+
react(),
|
|
38
|
+
dts(dtsPluginConfig),
|
|
39
|
+
...plugins
|
|
40
|
+
],
|
|
41
|
+
build: {
|
|
42
|
+
lib: {
|
|
43
|
+
entry: resolve(process.cwd(), entry),
|
|
44
|
+
name: libraryName,
|
|
45
|
+
formats,
|
|
46
|
+
fileName: (format) => {
|
|
47
|
+
if (format === "es") return "index.mjs";
|
|
48
|
+
if (format === "cjs") return "index.js";
|
|
49
|
+
return `index.${format}.js`;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
rollupOptions: {
|
|
53
|
+
external: allExternals,
|
|
54
|
+
output: {
|
|
55
|
+
globals: standardGlobals
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
sourcemap,
|
|
59
|
+
minify
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const mergedLib = {
|
|
63
|
+
...config.build?.lib,
|
|
64
|
+
...viteConfigOverrides.build?.lib
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
...config,
|
|
68
|
+
...viteConfigOverrides,
|
|
69
|
+
plugins: [...config.plugins ?? [], ...viteConfigOverrides.plugins ?? []],
|
|
70
|
+
build: {
|
|
71
|
+
...config.build,
|
|
72
|
+
...viteConfigOverrides.build,
|
|
73
|
+
lib: mergedLib.entry ? mergedLib : config.build?.lib,
|
|
74
|
+
rollupOptions: {
|
|
75
|
+
...config.build?.rollupOptions,
|
|
76
|
+
...viteConfigOverrides.build?.rollupOptions,
|
|
77
|
+
external: viteConfigOverrides.build?.rollupOptions?.external ?? allExternals,
|
|
78
|
+
output: {
|
|
79
|
+
...config.build?.rollupOptions?.output,
|
|
80
|
+
...viteConfigOverrides.build?.rollupOptions?.output
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
104
85
|
}
|
|
86
|
+
export {
|
|
87
|
+
createLibraryConfig
|
|
88
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codefluss/vite-config-lib",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shared Vite configuration for library builds",
|
|
6
|
-
"main": "./dist/vite.config.base.
|
|
6
|
+
"main": "./dist/vite.config.base.cjs",
|
|
7
|
+
"module": "./dist/vite.config.base.js",
|
|
7
8
|
"types": "./dist/vite.config.base.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
@@ -22,6 +23,7 @@
|
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"@types/node": "^24.10.3",
|
|
26
|
+
"tsup": "^8.5.0",
|
|
25
27
|
"typescript": "^5.9.3"
|
|
26
28
|
},
|
|
27
29
|
"keywords": [
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
"access": "public"
|
|
37
39
|
},
|
|
38
40
|
"scripts": {
|
|
39
|
-
"build": "
|
|
41
|
+
"build": "tsup vite.config.base.ts --format esm,cjs --dts --clean",
|
|
40
42
|
"clean": "rm -rf dist"
|
|
41
43
|
}
|
|
42
44
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite.config.base.d.ts","sourceRoot":"","sources":["../vite.config.base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAKrD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC;IAE5C;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;IAExC;;OAEG;IACH,GAAG,CAAC,EAAE;QACJ;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QAEnB;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QAEnB;;WAEG;QACH,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B,CAAC;IAEF;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IAEzB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,UAAU,CA8F7E"}
|