vite-config-factory 1.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.
Files changed (3) hide show
  1. package/index.d.ts +18 -0
  2. package/index.js +66 -0
  3. package/package.json +15 -0
package/index.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { UserConfigExport } from 'vite'
2
+
3
+ export interface ViteConfigFactoryOptions {
4
+ outDir?: string
5
+ manifestFile?: string
6
+ }
7
+
8
+ /**
9
+ * Create a reusable Vite config with a given entry object and options.
10
+ *
11
+ * @param entries An object mapping entry names to file paths
12
+ * @param options Optional build options
13
+ * @returns A Vite config export
14
+ */
15
+ export declare function createViteConfig(
16
+ entries: Record<string, string>,
17
+ options?: ViteConfigFactoryOptions
18
+ ): UserConfigExport
package/index.js ADDED
@@ -0,0 +1,66 @@
1
+ import { defineConfig } from 'vite'
2
+ import { resolve } from 'path'
3
+ import simpleManifest from 'vite-plugin-simple-manifest'
4
+
5
+ export function createViteConfig(entries, options = {}) {
6
+ const { outDir = 'dist', manifestFile = 'manifest.json' } = options
7
+ const { manifestPlugin } = simpleManifest
8
+
9
+ return defineConfig(({ mode }) => {
10
+ const isProduction = mode === 'production'
11
+
12
+ return {
13
+ build: {
14
+ outDir,
15
+ emptyOutDir: true,
16
+ rollupOptions: {
17
+ input: entries,
18
+ output: {
19
+ entryFileNames: isProduction ? '[name].[hash].js' : '[name].js',
20
+ chunkFileNames: isProduction ? '[name].[hash].js' : '[name].js',
21
+ assetFileNames: (assetInfo) => {
22
+ if (assetInfo.name?.endsWith('.css')) {
23
+ return isProduction ? '[name].[hash].css' : '[name].css'
24
+ }
25
+ return 'assets/[name].[hash].[ext]'
26
+ }
27
+ }
28
+ },
29
+ minify: isProduction ? 'esbuild' : false,
30
+ sourcemap: true
31
+ },
32
+ esbuild: {
33
+ keepNames: true,
34
+ minifyIdentifiers: false
35
+ },
36
+ css: {
37
+ preprocessorOptions: {
38
+ scss: {
39
+ api: 'modern-compiler',
40
+ includePaths: ['node_modules', 'source'],
41
+ importers: [
42
+ {
43
+ findFileUrl(url) {
44
+ if (url.startsWith('~')) {
45
+ return new URL(
46
+ url.slice(1),
47
+ new URL('../node_modules/', import.meta.url)
48
+ )
49
+ }
50
+ return null
51
+ }
52
+ }
53
+ ]
54
+ }
55
+ }
56
+ },
57
+ resolve: {
58
+ extensions: ['.tsx', '.ts', '.js', '.scss', '.css'],
59
+ alias: {
60
+ '~': resolve(process.cwd(), 'node_modules')
61
+ }
62
+ },
63
+ plugins: [manifestPlugin(manifestFile)]
64
+ }
65
+ })
66
+ }
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "vite-config-factory",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "description": "A simple Vite plugin for common vite config across multiple projects.",
6
+ "main": "index.js",
7
+ "keywords": ["vite", "plugin", "config", "factory"],
8
+ "author": "Sebastian Thulin",
9
+ "license": "MIT",
10
+ "peerDependencies": {
11
+ "vite": "^7.1.2",
12
+ "vite-plugin-simple-manifest": "^1.0.3"
13
+ },
14
+ "types": "index.d.ts"
15
+ }