@eventuras/vite-config 0.3.1 → 0.4.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/README.md +31 -9
- package/dist/react-lib.d.ts +4 -21
- package/dist/react-lib.js +5 -14
- package/dist/vanilla-lib.d.ts +3 -0
- package/dist/vanilla-lib.js +4 -8
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -10,7 +10,35 @@ This package provides reusable Vite configuration presets for different types of
|
|
|
10
10
|
|
|
11
11
|
- Node.js 24+
|
|
12
12
|
- Vite 7 or 8 (peer dependency)
|
|
13
|
-
- TypeScript 6 in the consuming package
|
|
13
|
+
- TypeScript 6 or 7 in the consuming package, used to emit declarations (see below)
|
|
14
|
+
|
|
15
|
+
## Type declarations
|
|
16
|
+
|
|
17
|
+
The presets build JavaScript only. Emit declarations with the TypeScript compiler
|
|
18
|
+
the package already has, **after** `vite build` (Vite empties `dist` first):
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "vite build && tsc --emitDeclarationOnly"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
With `@eventuras/typescript-config/library.json` or `react-library.json`,
|
|
29
|
+
`outDir` already resolves to the package's own `dist`. Otherwise set
|
|
30
|
+
`"outDir": "dist"` in the package's `tsconfig.json`.
|
|
31
|
+
|
|
32
|
+
Keep test and story files out of the emitted types: the shared base config
|
|
33
|
+
excludes them, but a package `tsconfig.json` that sets its own `exclude` replaces
|
|
34
|
+
that list. Re-add the patterns, or point the build at a `tsconfig.build.json`
|
|
35
|
+
that does (`tsc -p tsconfig.build.json --emitDeclarationOnly`).
|
|
36
|
+
|
|
37
|
+
`tsc` does not rewrite path aliases such as `@/…` in emitted declarations. Use
|
|
38
|
+
relative imports in anything reachable from a public export.
|
|
39
|
+
|
|
40
|
+
`vite build --watch` rebuilds JavaScript only. Run `tsc --emitDeclarationOnly --watch`
|
|
41
|
+
alongside it when you need live types.
|
|
14
42
|
|
|
15
43
|
## Presets
|
|
16
44
|
|
|
@@ -52,7 +80,6 @@ export default defineReactLibConfig({
|
|
|
52
80
|
|
|
53
81
|
**Features:**
|
|
54
82
|
- React plugin (Babel or SWC)
|
|
55
|
-
- TypeScript declaration generation
|
|
56
83
|
- Optional Tailwind CSS support
|
|
57
84
|
- 'use client' directive preservation for RSC
|
|
58
85
|
- Configurable module preservation
|
|
@@ -106,10 +133,6 @@ All presets support these options:
|
|
|
106
133
|
- **`preserveModules`**: Keep source structure in output (default: `true`)
|
|
107
134
|
- **`preserveUseClientDirectives`**: Preserve 'use client' for RSC (default: `true`)
|
|
108
135
|
- **`useSWC`**: Use SWC instead of Babel (default: `false`)
|
|
109
|
-
- **`dts`**: TypeScript declaration options
|
|
110
|
-
- `entryRoot`: Source root (default: `'src'`)
|
|
111
|
-
- `outDir`: Output directory (default: `'dist'`)
|
|
112
|
-
- `rollupTypes`: Bundle types into single file (default: `false`)
|
|
113
136
|
|
|
114
137
|
## Migration Guide
|
|
115
138
|
|
|
@@ -164,9 +187,8 @@ export default defineReactLibConfig({
|
|
|
164
187
|
## Troubleshooting
|
|
165
188
|
|
|
166
189
|
### Types not generated
|
|
167
|
-
-
|
|
168
|
-
-
|
|
169
|
-
- Check `dts.entryRoot` and `dts.outDir` options
|
|
190
|
+
- Since 0.4.0 the presets no longer emit declarations. Add `tsc --emitDeclarationOnly` after `vite build` in the package's build script (see [Type declarations](#type-declarations))
|
|
191
|
+
- If `.d.ts` files land outside the package, `outDir` is being resolved relative to a shared config. Upgrade `@eventuras/typescript-config`, or set `outDir` in the package's own `tsconfig.json`
|
|
170
192
|
|
|
171
193
|
### 'use client' directives missing
|
|
172
194
|
- Ensure `preserveUseClientDirectives: true` (default for Next.js)
|
package/dist/react-lib.d.ts
CHANGED
|
@@ -35,26 +35,6 @@ export interface ReactLibConfig {
|
|
|
35
35
|
* @default false
|
|
36
36
|
*/
|
|
37
37
|
useSWC?: boolean;
|
|
38
|
-
/**
|
|
39
|
-
* TypeScript declaration options.
|
|
40
|
-
*/
|
|
41
|
-
dts?: {
|
|
42
|
-
/**
|
|
43
|
-
* Entry root for DTS generation.
|
|
44
|
-
* @default 'src'
|
|
45
|
-
*/
|
|
46
|
-
entryRoot?: string;
|
|
47
|
-
/**
|
|
48
|
-
* Output directory for .d.ts files.
|
|
49
|
-
* @default 'dist'
|
|
50
|
-
*/
|
|
51
|
-
outDir?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Roll up types into a single .d.ts file.
|
|
54
|
-
* @default false
|
|
55
|
-
*/
|
|
56
|
-
rollupTypes?: boolean;
|
|
57
|
-
};
|
|
58
38
|
/**
|
|
59
39
|
* Additional Vite configuration to merge.
|
|
60
40
|
*/
|
|
@@ -62,6 +42,9 @@ export interface ReactLibConfig {
|
|
|
62
42
|
}
|
|
63
43
|
/**
|
|
64
44
|
* Vite configuration preset for React libraries.
|
|
65
|
-
* Includes React plugin
|
|
45
|
+
* Includes React plugin and common React externals.
|
|
46
|
+
*
|
|
47
|
+
* Emits JavaScript only. Declarations come from the package's own compiler:
|
|
48
|
+
* `vite build && tsc --emitDeclarationOnly`.
|
|
66
49
|
*/
|
|
67
50
|
export declare function defineReactLibConfig(config: ReactLibConfig): UserConfig;
|
package/dist/react-lib.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { defineConfig } from 'vite';
|
|
2
2
|
import react from '@vitejs/plugin-react';
|
|
3
3
|
import tailwindcss from '@tailwindcss/vite';
|
|
4
|
-
import dts from 'vite-plugin-dts';
|
|
5
4
|
import { resolve } from 'node:path';
|
|
6
5
|
import { glob } from 'glob';
|
|
7
6
|
import fs from 'node:fs';
|
|
@@ -62,10 +61,13 @@ function preserveUseClient() {
|
|
|
62
61
|
}
|
|
63
62
|
/**
|
|
64
63
|
* Vite configuration preset for React libraries.
|
|
65
|
-
* Includes React plugin
|
|
64
|
+
* Includes React plugin and common React externals.
|
|
65
|
+
*
|
|
66
|
+
* Emits JavaScript only. Declarations come from the package's own compiler:
|
|
67
|
+
* `vite build && tsc --emitDeclarationOnly`.
|
|
66
68
|
*/
|
|
67
69
|
export function defineReactLibConfig(config) {
|
|
68
|
-
const { entry, external, tailwind = false, preserveModules = true, preserveUseClientDirectives = true, useSWC = false,
|
|
70
|
+
const { entry, external, tailwind = false, preserveModules = true, preserveUseClientDirectives = true, useSWC = false, viteConfig = {}, } = config;
|
|
69
71
|
const autoExternals = external === false ? [] : getRuntimeDependencyExternals();
|
|
70
72
|
const userExternals = Array.isArray(external) ? external : [];
|
|
71
73
|
// Determine entry points
|
|
@@ -95,17 +97,6 @@ export function defineReactLibConfig(config) {
|
|
|
95
97
|
if (tailwind) {
|
|
96
98
|
plugins.push(tailwindcss());
|
|
97
99
|
}
|
|
98
|
-
// Add DTS plugin
|
|
99
|
-
plugins.push(dts({
|
|
100
|
-
entryRoot: dtsOptions.entryRoot || 'src',
|
|
101
|
-
// vite-plugin-dts v5 renamed `outDir` -> `outDirs` and
|
|
102
|
-
// `rollupTypes` -> `bundleTypes`; the preset keeps the old names.
|
|
103
|
-
outDirs: dtsOptions.outDir || 'dist',
|
|
104
|
-
include: ['src/**/*'],
|
|
105
|
-
exclude: ['**/*.test.ts', '**/*.test.tsx', '**/*.spec.ts', '**/*.spec.tsx', '**/*.stories.tsx'],
|
|
106
|
-
copyDtsFiles: true,
|
|
107
|
-
bundleTypes: dtsOptions.rollupTypes || false,
|
|
108
|
-
}));
|
|
109
100
|
// Add use client preservation if enabled
|
|
110
101
|
if (preserveUseClientDirectives) {
|
|
111
102
|
plugins.push(preserveUseClient());
|
package/dist/vanilla-lib.d.ts
CHANGED
|
@@ -31,5 +31,8 @@ export interface VanillaLibConfig {
|
|
|
31
31
|
* - Minification is OFF — consumers minify their own bundle, and unminified
|
|
32
32
|
* output preserves class names (so `instanceof` and stack traces work).
|
|
33
33
|
* - Sourcemaps ON for debuggable consumer stack traces.
|
|
34
|
+
*
|
|
35
|
+
* Emits JavaScript only. Declarations come from the package's own compiler:
|
|
36
|
+
* `vite build && tsc --emitDeclarationOnly`.
|
|
34
37
|
*/
|
|
35
38
|
export declare function defineVanillaLibConfig(config: VanillaLibConfig): UserConfig;
|
package/dist/vanilla-lib.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { defineConfig } from 'vite';
|
|
2
|
-
import dts from 'vite-plugin-dts';
|
|
3
2
|
import { resolve } from 'node:path';
|
|
4
3
|
import { getRuntimeDependencyExternals, NODE_BUILTINS_EXTERNAL } from './externals.js';
|
|
5
4
|
/**
|
|
@@ -12,19 +11,16 @@ import { getRuntimeDependencyExternals, NODE_BUILTINS_EXTERNAL } from './externa
|
|
|
12
11
|
* - Minification is OFF — consumers minify their own bundle, and unminified
|
|
13
12
|
* output preserves class names (so `instanceof` and stack traces work).
|
|
14
13
|
* - Sourcemaps ON for debuggable consumer stack traces.
|
|
14
|
+
*
|
|
15
|
+
* Emits JavaScript only. Declarations come from the package's own compiler:
|
|
16
|
+
* `vite build && tsc --emitDeclarationOnly`.
|
|
15
17
|
*/
|
|
16
18
|
export function defineVanillaLibConfig(config) {
|
|
17
19
|
const { entry, name, external, viteConfig = {} } = config;
|
|
18
20
|
const autoExternals = external === false ? [] : getRuntimeDependencyExternals();
|
|
19
21
|
const userExternals = Array.isArray(external) ? external : [];
|
|
20
22
|
return defineConfig({
|
|
21
|
-
plugins: [
|
|
22
|
-
dts({
|
|
23
|
-
include: ['src/**/*'],
|
|
24
|
-
exclude: ['**/*.test.ts', '**/*.test.tsx', '**/*.spec.ts', '**/*.spec.tsx'],
|
|
25
|
-
}),
|
|
26
|
-
...(viteConfig.plugins || []),
|
|
27
|
-
],
|
|
23
|
+
plugins: [...(viteConfig.plugins || [])],
|
|
28
24
|
build: {
|
|
29
25
|
minify: false,
|
|
30
26
|
sourcemap: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventuras/vite-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,14 +33,13 @@
|
|
|
33
33
|
"@tailwindcss/vite": "^4.3.2",
|
|
34
34
|
"@vitejs/plugin-react": "^6.0.3",
|
|
35
35
|
"@vitejs/plugin-react-swc": "^4.3.0",
|
|
36
|
-
"glob": "^13.0.6"
|
|
37
|
-
"vite-plugin-dts": "^5.0.3"
|
|
36
|
+
"glob": "^13.0.6"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
39
|
"@types/node": "^24.12.0",
|
|
41
40
|
"typescript": "^6.0.2",
|
|
42
41
|
"vite": "^8.1.0",
|
|
43
|
-
"@eventuras/typescript-config": "1.
|
|
42
|
+
"@eventuras/typescript-config": "1.1.0"
|
|
44
43
|
},
|
|
45
44
|
"peerDependencies": {
|
|
46
45
|
"vite": "^7.0.0 || ^8.0.0"
|