@jmlweb/vite-config 0.0.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 ADDED
@@ -0,0 +1,272 @@
1
+ # @jmlweb/vite-config
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@jmlweb/vite-config)](https://www.npmjs.com/package/@jmlweb/vite-config)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18.0.0-339933.svg)](https://nodejs.org/)
6
+ [![Vite](https://img.shields.io/badge/Vite-5.0%2B-646CFF.svg)](https://vite.dev/)
7
+
8
+ > Base Vite configuration for jmlweb projects. Provides sensible defaults for TypeScript support, build optimization, and development server settings.
9
+
10
+ ## Features
11
+
12
+ - **Sensible Defaults**: Pre-configured with optimized build and dev server settings
13
+ - **TypeScript Support**: Works seamlessly with TypeScript projects
14
+ - **React Ready**: Optional React integration via plugin injection
15
+ - **Path Aliases**: Easy configuration for module path resolution
16
+ - **Clean API**: Simple functions to create configurations
17
+ - **Fully Typed**: Complete TypeScript support with exported types
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install --save-dev @jmlweb/vite-config vite
23
+ ```
24
+
25
+ For React projects, also install the React plugin:
26
+
27
+ ```bash
28
+ npm install --save-dev @vitejs/plugin-react
29
+ ```
30
+
31
+ ## Quick Start
32
+
33
+ Create a `vite.config.ts` file in your project root:
34
+
35
+ ```typescript
36
+ import { createViteConfig } from '@jmlweb/vite-config';
37
+
38
+ export default createViteConfig();
39
+ ```
40
+
41
+ ## Examples
42
+
43
+ ### Basic Setup
44
+
45
+ ```typescript
46
+ // vite.config.ts
47
+ import { createViteConfig } from '@jmlweb/vite-config';
48
+
49
+ export default createViteConfig();
50
+ ```
51
+
52
+ ### With Path Aliases
53
+
54
+ ```typescript
55
+ // vite.config.ts
56
+ import { createViteConfig } from '@jmlweb/vite-config';
57
+ import { resolve } from 'path';
58
+
59
+ export default createViteConfig({
60
+ resolve: {
61
+ alias: {
62
+ '@': resolve(__dirname, './src'),
63
+ '@components': resolve(__dirname, './src/components'),
64
+ '@utils': resolve(__dirname, './src/utils'),
65
+ },
66
+ },
67
+ });
68
+ ```
69
+
70
+ ### With React Plugin
71
+
72
+ ```typescript
73
+ // vite.config.ts
74
+ import { createViteConfig } from '@jmlweb/vite-config';
75
+ import react from '@vitejs/plugin-react';
76
+
77
+ export default createViteConfig({
78
+ plugins: [react()],
79
+ });
80
+ ```
81
+
82
+ ### Using the React-Specific Helper
83
+
84
+ ```typescript
85
+ // vite.config.ts
86
+ import { createReactViteConfig } from '@jmlweb/vite-config';
87
+ import react from '@vitejs/plugin-react';
88
+
89
+ export default createReactViteConfig({
90
+ reactPlugin: react(),
91
+ resolve: {
92
+ alias: {
93
+ '@': './src',
94
+ },
95
+ },
96
+ });
97
+ ```
98
+
99
+ ### With Custom Build Settings
100
+
101
+ ```typescript
102
+ // vite.config.ts
103
+ import { createViteConfig } from '@jmlweb/vite-config';
104
+
105
+ export default createViteConfig({
106
+ build: {
107
+ sourcemap: true,
108
+ target: ['es2020', 'chrome87', 'firefox78', 'safari14'],
109
+ outDir: 'build',
110
+ },
111
+ });
112
+ ```
113
+
114
+ ### With Custom Server Settings
115
+
116
+ ```typescript
117
+ // vite.config.ts
118
+ import { createViteConfig } from '@jmlweb/vite-config';
119
+
120
+ export default createViteConfig({
121
+ server: {
122
+ port: 3000,
123
+ open: true,
124
+ host: true, // Listen on all addresses
125
+ },
126
+ });
127
+ ```
128
+
129
+ ### With Multiple Plugins
130
+
131
+ ```typescript
132
+ // vite.config.ts
133
+ import { createViteConfig } from '@jmlweb/vite-config';
134
+ import react from '@vitejs/plugin-react';
135
+ import svgr from 'vite-plugin-svgr';
136
+
137
+ export default createViteConfig({
138
+ plugins: [react(), svgr()],
139
+ resolve: {
140
+ alias: {
141
+ '@': './src',
142
+ },
143
+ },
144
+ });
145
+ ```
146
+
147
+ ### Full Configuration Example
148
+
149
+ ```typescript
150
+ // vite.config.ts
151
+ import { createViteConfig } from '@jmlweb/vite-config';
152
+ import react from '@vitejs/plugin-react';
153
+ import { resolve } from 'path';
154
+
155
+ export default createViteConfig({
156
+ plugins: [
157
+ react({
158
+ babel: {
159
+ plugins: ['@emotion/babel-plugin'],
160
+ },
161
+ }),
162
+ ],
163
+ resolve: {
164
+ alias: {
165
+ '@': resolve(__dirname, './src'),
166
+ },
167
+ },
168
+ build: {
169
+ sourcemap: true,
170
+ target: 'es2020',
171
+ },
172
+ server: {
173
+ port: 3000,
174
+ open: true,
175
+ },
176
+ preview: {
177
+ port: 4000,
178
+ },
179
+ });
180
+ ```
181
+
182
+ ## Configuration Details
183
+
184
+ ### Default Settings
185
+
186
+ | Category | Setting | Default Value | Description |
187
+ | -------- | ------------ | ------------- | ------------------------------- |
188
+ | Build | `outDir` | `'dist'` | Output directory for production |
189
+ | Build | `sourcemap` | `false` | Source map generation |
190
+ | Build | `minify` | `'esbuild'` | Minification strategy |
191
+ | Build | `target` | `'esnext'` | Build target environment |
192
+ | Server | `port` | `5173` | Development server port |
193
+ | Server | `strictPort` | `false` | Fail if port is in use |
194
+ | Server | `open` | `false` | Open browser on start |
195
+ | Server | `host` | `'localhost'` | Host to bind to |
196
+ | Preview | `port` | `4173` | Preview server port |
197
+
198
+ ### API Reference
199
+
200
+ #### `createViteConfig(options?: ViteConfigOptions): UserConfig`
201
+
202
+ Creates a Vite configuration with sensible defaults.
203
+
204
+ **Parameters:**
205
+
206
+ | Option | Type | Description |
207
+ | --------- | ------------------------- | -------------------------------- |
208
+ | `plugins` | `Plugin[]` | Vite plugins to include |
209
+ | `resolve` | `{ alias?: Record<...> }` | Module resolution configuration |
210
+ | `build` | `BuildOptions` | Build configuration options |
211
+ | `server` | `ServerOptions` | Development server configuration |
212
+ | `preview` | `PreviewOptions` | Preview server configuration |
213
+ | `options` | `Partial<UserConfig>` | Additional Vite options to merge |
214
+
215
+ **Returns:** A complete Vite `UserConfig` object.
216
+
217
+ #### `createReactViteConfig(options: ViteConfigOptions & { reactPlugin: Plugin }): UserConfig`
218
+
219
+ Creates a Vite configuration optimized for React applications.
220
+
221
+ **Parameters:**
222
+
223
+ | Option | Type | Description |
224
+ | ------------- | ------------------- | ------------------------------------ |
225
+ | `reactPlugin` | `Plugin` | The React plugin instance (required) |
226
+ | ... | `ViteConfigOptions` | All options from `createViteConfig` |
227
+
228
+ **Returns:** A complete Vite `UserConfig` object with React plugin included.
229
+
230
+ #### `BASE_DEFAULTS`
231
+
232
+ Exported constant containing the default configuration values for reference.
233
+
234
+ #### `UserConfig`, `Plugin` (re-exported from Vite)
235
+
236
+ Vite types are re-exported for convenience when extending configurations.
237
+
238
+ ## When to Use
239
+
240
+ Use this configuration when you want:
241
+
242
+ - Consistent Vite configuration across multiple projects
243
+ - Optimized build settings out of the box
244
+ - Easy integration with React and other plugins
245
+ - Type-safe configuration with full TypeScript support
246
+ - A clean, simple API for customization
247
+
248
+ ## Requirements
249
+
250
+ - **Node.js** >= 18.0.0
251
+ - **Vite** >= 5.0.0
252
+
253
+ ## Peer Dependencies
254
+
255
+ This package requires the following peer dependency:
256
+
257
+ - `vite` (>=5.0.0)
258
+
259
+ Optional peer dependency for React projects:
260
+
261
+ - `@vitejs/plugin-react` (for React integration)
262
+
263
+ ## Related Packages
264
+
265
+ - [`@jmlweb/tsconfig-react`](../tsconfig-react) - TypeScript config for React projects
266
+ - [`@jmlweb/eslint-config-react`](../eslint-config-react) - ESLint config for React projects
267
+ - [`@jmlweb/vitest-config`](../vitest-config) - Vitest configuration for testing
268
+ - [`@jmlweb/prettier-config-base`](../prettier-config-base) - Prettier config for consistent formatting
269
+
270
+ ## License
271
+
272
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ BASE_DEFAULTS: () => BASE_DEFAULTS,
24
+ createReactViteConfig: () => createReactViteConfig,
25
+ createViteConfig: () => createViteConfig
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+ var BASE_DEFAULTS = {
29
+ build: {
30
+ outDir: "dist",
31
+ sourcemap: false,
32
+ minify: "esbuild",
33
+ target: "esnext",
34
+ rollupOptions: {
35
+ output: {
36
+ manualChunks: void 0
37
+ }
38
+ }
39
+ },
40
+ server: {
41
+ port: 5173,
42
+ strictPort: false,
43
+ open: false,
44
+ host: "localhost"
45
+ },
46
+ preview: {
47
+ port: 4173
48
+ }
49
+ };
50
+ var createViteConfig = (config = {}) => {
51
+ const {
52
+ plugins = [],
53
+ resolve,
54
+ build = {},
55
+ server = {},
56
+ preview = {},
57
+ options = {}
58
+ } = config;
59
+ return {
60
+ plugins,
61
+ ...resolve && { resolve },
62
+ build: {
63
+ ...BASE_DEFAULTS.build,
64
+ ...build
65
+ },
66
+ server: {
67
+ ...BASE_DEFAULTS.server,
68
+ ...server
69
+ },
70
+ preview: {
71
+ ...BASE_DEFAULTS.preview,
72
+ ...preview
73
+ },
74
+ ...options
75
+ };
76
+ };
77
+ var createReactViteConfig = (config) => {
78
+ const { reactPlugin, plugins = [], ...rest } = config;
79
+ return createViteConfig({
80
+ ...rest,
81
+ plugins: [reactPlugin, ...plugins]
82
+ });
83
+ };
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ BASE_DEFAULTS,
87
+ createReactViteConfig,
88
+ createViteConfig
89
+ });
@@ -0,0 +1,207 @@
1
+ import { Plugin, UserConfig } from 'vite';
2
+ export { Plugin, UserConfig } from 'vite';
3
+
4
+ /**
5
+ * Options for creating a base Vite configuration
6
+ */
7
+ interface ViteConfigOptions {
8
+ /**
9
+ * Additional Vite plugins to include
10
+ * @default []
11
+ */
12
+ plugins?: Plugin[];
13
+ /**
14
+ * Path aliases for module resolution
15
+ * @example { '@': './src' }
16
+ */
17
+ resolve?: {
18
+ alias?: Record<string, string>;
19
+ };
20
+ /**
21
+ * Build configuration options
22
+ */
23
+ build?: {
24
+ /**
25
+ * Output directory for production build
26
+ * @default 'dist'
27
+ */
28
+ outDir?: string;
29
+ /**
30
+ * Enable/disable source maps
31
+ * @default false
32
+ */
33
+ sourcemap?: boolean | 'inline' | 'hidden';
34
+ /**
35
+ * Minification option
36
+ * @default 'esbuild'
37
+ */
38
+ minify?: boolean | 'esbuild' | 'terser';
39
+ /**
40
+ * Target environment for build
41
+ * @default 'esnext'
42
+ */
43
+ target?: string | string[];
44
+ };
45
+ /**
46
+ * Development server configuration
47
+ */
48
+ server?: {
49
+ /**
50
+ * Server port
51
+ * @default 5173
52
+ */
53
+ port?: number;
54
+ /**
55
+ * Enable strict port (fail if port is in use)
56
+ * @default false
57
+ */
58
+ strictPort?: boolean;
59
+ /**
60
+ * Open browser on server start
61
+ * @default false
62
+ */
63
+ open?: boolean;
64
+ /**
65
+ * Host to bind to
66
+ * @default 'localhost'
67
+ */
68
+ host?: string | boolean;
69
+ };
70
+ /**
71
+ * Preview server configuration (for previewing production build)
72
+ */
73
+ preview?: {
74
+ /**
75
+ * Preview server port
76
+ * @default 4173
77
+ */
78
+ port?: number;
79
+ };
80
+ /**
81
+ * Additional Vite configuration to merge
82
+ */
83
+ options?: Omit<UserConfig, 'plugins' | 'resolve' | 'build' | 'server' | 'preview'>;
84
+ }
85
+ /**
86
+ * Base Vite configuration defaults used across all @jmlweb projects
87
+ */
88
+ declare const BASE_DEFAULTS: {
89
+ build: {
90
+ outDir: string;
91
+ sourcemap: false;
92
+ minify: "esbuild";
93
+ target: string;
94
+ rollupOptions: {
95
+ output: {
96
+ manualChunks: undefined;
97
+ };
98
+ };
99
+ };
100
+ server: {
101
+ port: number;
102
+ strictPort: false;
103
+ open: false;
104
+ host: string;
105
+ };
106
+ preview: {
107
+ port: number;
108
+ };
109
+ };
110
+ /**
111
+ * Creates a base Vite configuration with sensible defaults
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * // Simple usage
116
+ * import { createViteConfig } from '@jmlweb/vite-config';
117
+ * export default createViteConfig();
118
+ * ```
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * // With path aliases
123
+ * import { createViteConfig } from '@jmlweb/vite-config';
124
+ * import { resolve } from 'path';
125
+ *
126
+ * export default createViteConfig({
127
+ * resolve: {
128
+ * alias: {
129
+ * '@': resolve(__dirname, './src'),
130
+ * },
131
+ * },
132
+ * });
133
+ * ```
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * // With React plugin
138
+ * import { createViteConfig } from '@jmlweb/vite-config';
139
+ * import react from '@vitejs/plugin-react';
140
+ *
141
+ * export default createViteConfig({
142
+ * plugins: [react()],
143
+ * });
144
+ * ```
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // With custom build options
149
+ * import { createViteConfig } from '@jmlweb/vite-config';
150
+ *
151
+ * export default createViteConfig({
152
+ * build: {
153
+ * sourcemap: true,
154
+ * target: ['es2020', 'chrome87', 'firefox78', 'safari14'],
155
+ * },
156
+ * server: {
157
+ * port: 3000,
158
+ * open: true,
159
+ * },
160
+ * });
161
+ * ```
162
+ */
163
+ declare const createViteConfig: (config?: ViteConfigOptions) => UserConfig;
164
+ /**
165
+ * Creates a Vite configuration optimized for React applications
166
+ *
167
+ * This is a convenience function that combines the base configuration
168
+ * with React-specific settings. You must provide the React plugin.
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * import { createReactViteConfig } from '@jmlweb/vite-config';
173
+ * import react from '@vitejs/plugin-react';
174
+ *
175
+ * export default createReactViteConfig({
176
+ * reactPlugin: react(),
177
+ * resolve: {
178
+ * alias: {
179
+ * '@': './src',
180
+ * },
181
+ * },
182
+ * });
183
+ * ```
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // With custom React plugin options
188
+ * import { createReactViteConfig } from '@jmlweb/vite-config';
189
+ * import react from '@vitejs/plugin-react';
190
+ *
191
+ * export default createReactViteConfig({
192
+ * reactPlugin: react({
193
+ * babel: {
194
+ * plugins: ['@emotion/babel-plugin'],
195
+ * },
196
+ * }),
197
+ * build: {
198
+ * sourcemap: true,
199
+ * },
200
+ * });
201
+ * ```
202
+ */
203
+ declare const createReactViteConfig: (config: ViteConfigOptions & {
204
+ reactPlugin: Plugin;
205
+ }) => UserConfig;
206
+
207
+ export { BASE_DEFAULTS, type ViteConfigOptions, createReactViteConfig, createViteConfig };
@@ -0,0 +1,207 @@
1
+ import { Plugin, UserConfig } from 'vite';
2
+ export { Plugin, UserConfig } from 'vite';
3
+
4
+ /**
5
+ * Options for creating a base Vite configuration
6
+ */
7
+ interface ViteConfigOptions {
8
+ /**
9
+ * Additional Vite plugins to include
10
+ * @default []
11
+ */
12
+ plugins?: Plugin[];
13
+ /**
14
+ * Path aliases for module resolution
15
+ * @example { '@': './src' }
16
+ */
17
+ resolve?: {
18
+ alias?: Record<string, string>;
19
+ };
20
+ /**
21
+ * Build configuration options
22
+ */
23
+ build?: {
24
+ /**
25
+ * Output directory for production build
26
+ * @default 'dist'
27
+ */
28
+ outDir?: string;
29
+ /**
30
+ * Enable/disable source maps
31
+ * @default false
32
+ */
33
+ sourcemap?: boolean | 'inline' | 'hidden';
34
+ /**
35
+ * Minification option
36
+ * @default 'esbuild'
37
+ */
38
+ minify?: boolean | 'esbuild' | 'terser';
39
+ /**
40
+ * Target environment for build
41
+ * @default 'esnext'
42
+ */
43
+ target?: string | string[];
44
+ };
45
+ /**
46
+ * Development server configuration
47
+ */
48
+ server?: {
49
+ /**
50
+ * Server port
51
+ * @default 5173
52
+ */
53
+ port?: number;
54
+ /**
55
+ * Enable strict port (fail if port is in use)
56
+ * @default false
57
+ */
58
+ strictPort?: boolean;
59
+ /**
60
+ * Open browser on server start
61
+ * @default false
62
+ */
63
+ open?: boolean;
64
+ /**
65
+ * Host to bind to
66
+ * @default 'localhost'
67
+ */
68
+ host?: string | boolean;
69
+ };
70
+ /**
71
+ * Preview server configuration (for previewing production build)
72
+ */
73
+ preview?: {
74
+ /**
75
+ * Preview server port
76
+ * @default 4173
77
+ */
78
+ port?: number;
79
+ };
80
+ /**
81
+ * Additional Vite configuration to merge
82
+ */
83
+ options?: Omit<UserConfig, 'plugins' | 'resolve' | 'build' | 'server' | 'preview'>;
84
+ }
85
+ /**
86
+ * Base Vite configuration defaults used across all @jmlweb projects
87
+ */
88
+ declare const BASE_DEFAULTS: {
89
+ build: {
90
+ outDir: string;
91
+ sourcemap: false;
92
+ minify: "esbuild";
93
+ target: string;
94
+ rollupOptions: {
95
+ output: {
96
+ manualChunks: undefined;
97
+ };
98
+ };
99
+ };
100
+ server: {
101
+ port: number;
102
+ strictPort: false;
103
+ open: false;
104
+ host: string;
105
+ };
106
+ preview: {
107
+ port: number;
108
+ };
109
+ };
110
+ /**
111
+ * Creates a base Vite configuration with sensible defaults
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * // Simple usage
116
+ * import { createViteConfig } from '@jmlweb/vite-config';
117
+ * export default createViteConfig();
118
+ * ```
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * // With path aliases
123
+ * import { createViteConfig } from '@jmlweb/vite-config';
124
+ * import { resolve } from 'path';
125
+ *
126
+ * export default createViteConfig({
127
+ * resolve: {
128
+ * alias: {
129
+ * '@': resolve(__dirname, './src'),
130
+ * },
131
+ * },
132
+ * });
133
+ * ```
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * // With React plugin
138
+ * import { createViteConfig } from '@jmlweb/vite-config';
139
+ * import react from '@vitejs/plugin-react';
140
+ *
141
+ * export default createViteConfig({
142
+ * plugins: [react()],
143
+ * });
144
+ * ```
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // With custom build options
149
+ * import { createViteConfig } from '@jmlweb/vite-config';
150
+ *
151
+ * export default createViteConfig({
152
+ * build: {
153
+ * sourcemap: true,
154
+ * target: ['es2020', 'chrome87', 'firefox78', 'safari14'],
155
+ * },
156
+ * server: {
157
+ * port: 3000,
158
+ * open: true,
159
+ * },
160
+ * });
161
+ * ```
162
+ */
163
+ declare const createViteConfig: (config?: ViteConfigOptions) => UserConfig;
164
+ /**
165
+ * Creates a Vite configuration optimized for React applications
166
+ *
167
+ * This is a convenience function that combines the base configuration
168
+ * with React-specific settings. You must provide the React plugin.
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * import { createReactViteConfig } from '@jmlweb/vite-config';
173
+ * import react from '@vitejs/plugin-react';
174
+ *
175
+ * export default createReactViteConfig({
176
+ * reactPlugin: react(),
177
+ * resolve: {
178
+ * alias: {
179
+ * '@': './src',
180
+ * },
181
+ * },
182
+ * });
183
+ * ```
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // With custom React plugin options
188
+ * import { createReactViteConfig } from '@jmlweb/vite-config';
189
+ * import react from '@vitejs/plugin-react';
190
+ *
191
+ * export default createReactViteConfig({
192
+ * reactPlugin: react({
193
+ * babel: {
194
+ * plugins: ['@emotion/babel-plugin'],
195
+ * },
196
+ * }),
197
+ * build: {
198
+ * sourcemap: true,
199
+ * },
200
+ * });
201
+ * ```
202
+ */
203
+ declare const createReactViteConfig: (config: ViteConfigOptions & {
204
+ reactPlugin: Plugin;
205
+ }) => UserConfig;
206
+
207
+ export { BASE_DEFAULTS, type ViteConfigOptions, createReactViteConfig, createViteConfig };
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ // src/index.ts
2
+ var BASE_DEFAULTS = {
3
+ build: {
4
+ outDir: "dist",
5
+ sourcemap: false,
6
+ minify: "esbuild",
7
+ target: "esnext",
8
+ rollupOptions: {
9
+ output: {
10
+ manualChunks: void 0
11
+ }
12
+ }
13
+ },
14
+ server: {
15
+ port: 5173,
16
+ strictPort: false,
17
+ open: false,
18
+ host: "localhost"
19
+ },
20
+ preview: {
21
+ port: 4173
22
+ }
23
+ };
24
+ var createViteConfig = (config = {}) => {
25
+ const {
26
+ plugins = [],
27
+ resolve,
28
+ build = {},
29
+ server = {},
30
+ preview = {},
31
+ options = {}
32
+ } = config;
33
+ return {
34
+ plugins,
35
+ ...resolve && { resolve },
36
+ build: {
37
+ ...BASE_DEFAULTS.build,
38
+ ...build
39
+ },
40
+ server: {
41
+ ...BASE_DEFAULTS.server,
42
+ ...server
43
+ },
44
+ preview: {
45
+ ...BASE_DEFAULTS.preview,
46
+ ...preview
47
+ },
48
+ ...options
49
+ };
50
+ };
51
+ var createReactViteConfig = (config) => {
52
+ const { reactPlugin, plugins = [], ...rest } = config;
53
+ return createViteConfig({
54
+ ...rest,
55
+ plugins: [reactPlugin, ...plugins]
56
+ });
57
+ };
58
+ export {
59
+ BASE_DEFAULTS,
60
+ createReactViteConfig,
61
+ createViteConfig
62
+ };
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@jmlweb/vite-config",
3
+ "version": "0.0.0",
4
+ "description": "Base Vite configuration for jmlweb projects with TypeScript support, build optimization, and optional React integration",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "CHANGELOG.md"
25
+ ],
26
+ "keywords": [
27
+ "build",
28
+ "bundler",
29
+ "config",
30
+ "vite",
31
+ "vite-config"
32
+ ],
33
+ "author": "jmlweb",
34
+ "license": "MIT",
35
+ "repository": "jmlweb/tooling.git",
36
+ "bugs": "https://github.com/jmlweb/tooling/issues",
37
+ "homepage": "https://github.com/jmlweb/tooling/tree/main/packages/vite-config#readme",
38
+ "engines": {
39
+ "node": ">=18.0.0"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "peerDependencies": {
45
+ "vite": ">=5.0.0"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "@vitejs/plugin-react": {
49
+ "optional": true
50
+ }
51
+ },
52
+ "devDependencies": {
53
+ "@vitejs/plugin-react": "^4.3.4",
54
+ "tsup": "^8.5.1",
55
+ "typescript": "^5.9.3",
56
+ "vite": "^6.0.7",
57
+ "@jmlweb/tsconfig-internal": "0.0.1"
58
+ },
59
+ "scripts": {
60
+ "build": "tsup",
61
+ "clean": "rm -rf dist"
62
+ }
63
+ }