@uniweb/build 0.1.8 → 0.1.9
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/package.json +3 -1
- package/src/foundation/config.js +144 -0
- package/src/foundation/index.js +9 -0
- package/src/index.js +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
"./images": "./src/images.js",
|
|
10
10
|
"./generate-entry": "./src/generate-entry.js",
|
|
11
11
|
"./vite-plugin": "./src/vite-foundation-plugin.js",
|
|
12
|
+
"./foundation": "./src/foundation/index.js",
|
|
13
|
+
"./foundation/config": "./src/foundation/config.js",
|
|
12
14
|
"./site": "./src/site/index.js",
|
|
13
15
|
"./site/config": "./src/site/config.js",
|
|
14
16
|
"./dev": "./src/dev/index.js",
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Foundation Vite Configuration
|
|
3
|
+
*
|
|
4
|
+
* Provides a zero-config or minimal-config Vite setup for Uniweb foundations.
|
|
5
|
+
* Handles library mode, externals, and standard plugins.
|
|
6
|
+
*
|
|
7
|
+
* @module @uniweb/build/foundation/config
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // Minimal vite.config.js (recommended)
|
|
11
|
+
* import { defineFoundationConfig } from '@uniweb/build'
|
|
12
|
+
*
|
|
13
|
+
* export default defineFoundationConfig()
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // With customization
|
|
17
|
+
* import { defineFoundationConfig } from '@uniweb/build'
|
|
18
|
+
*
|
|
19
|
+
* export default defineFoundationConfig({
|
|
20
|
+
* entry: 'src/custom-entry.js',
|
|
21
|
+
* externals: ['lodash'],
|
|
22
|
+
* plugins: [myPlugin()],
|
|
23
|
+
* })
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { resolve } from 'node:path'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Default externals for foundations
|
|
30
|
+
* These are not bundled into the foundation output
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Default externals for foundations
|
|
34
|
+
* These are provided by the runtime and should not be bundled
|
|
35
|
+
*/
|
|
36
|
+
const DEFAULT_EXTERNALS = [
|
|
37
|
+
'react',
|
|
38
|
+
'react-dom',
|
|
39
|
+
'react/jsx-runtime',
|
|
40
|
+
'react/jsx-dev-runtime',
|
|
41
|
+
'@uniweb/core'
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Create a complete Vite configuration for a Uniweb foundation
|
|
46
|
+
*
|
|
47
|
+
* @param {Object} [options={}] - Configuration options
|
|
48
|
+
* @param {string} [options.entry] - Entry point path (default: 'src/entry-runtime.js')
|
|
49
|
+
* @param {string} [options.fileName] - Output file name (default: 'foundation')
|
|
50
|
+
* @param {string[]} [options.externals] - Additional packages to externalize
|
|
51
|
+
* @param {boolean} [options.includeDefaultExternals] - Include default externals (default: true)
|
|
52
|
+
* @param {Array} [options.plugins] - Additional Vite plugins
|
|
53
|
+
* @param {boolean} [options.tailwind] - Include Tailwind CSS v4 plugin (default: true)
|
|
54
|
+
* @param {boolean} [options.sourcemap] - Generate sourcemaps (default: true)
|
|
55
|
+
* @param {Object} [options.build] - Additional build options to merge
|
|
56
|
+
* @returns {Promise<Object>} Vite configuration
|
|
57
|
+
*/
|
|
58
|
+
export async function defineFoundationConfig(options = {}) {
|
|
59
|
+
const {
|
|
60
|
+
entry = 'src/entry-runtime.js',
|
|
61
|
+
fileName = 'foundation',
|
|
62
|
+
externals: additionalExternals = [],
|
|
63
|
+
includeDefaultExternals = true,
|
|
64
|
+
plugins: extraPlugins = [],
|
|
65
|
+
tailwind = true,
|
|
66
|
+
sourcemap = true,
|
|
67
|
+
build: buildOverrides = {},
|
|
68
|
+
...restOptions
|
|
69
|
+
} = options
|
|
70
|
+
|
|
71
|
+
// Determine foundation root (where vite.config.js is)
|
|
72
|
+
const foundationRoot = process.cwd()
|
|
73
|
+
|
|
74
|
+
// Build externals list
|
|
75
|
+
const externals = includeDefaultExternals
|
|
76
|
+
? [...DEFAULT_EXTERNALS, ...additionalExternals]
|
|
77
|
+
: additionalExternals
|
|
78
|
+
|
|
79
|
+
// Dynamic imports for optional peer dependencies
|
|
80
|
+
const imports = [
|
|
81
|
+
import('@vitejs/plugin-react'),
|
|
82
|
+
import('vite-plugin-svgr')
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
// Only import tailwind if enabled
|
|
86
|
+
if (tailwind) {
|
|
87
|
+
imports.unshift(import('@tailwindcss/vite'))
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const modules = await Promise.all(imports)
|
|
91
|
+
|
|
92
|
+
// Extract plugins based on what was imported
|
|
93
|
+
let tailwindcss, react, svgr
|
|
94
|
+
if (tailwind) {
|
|
95
|
+
tailwindcss = modules[0].default
|
|
96
|
+
react = modules[1].default
|
|
97
|
+
svgr = modules[2].default
|
|
98
|
+
} else {
|
|
99
|
+
react = modules[0].default
|
|
100
|
+
svgr = modules[1].default
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Build the plugins array
|
|
104
|
+
const plugins = [
|
|
105
|
+
tailwind && tailwindcss(),
|
|
106
|
+
react(),
|
|
107
|
+
svgr(),
|
|
108
|
+
...extraPlugins
|
|
109
|
+
].filter(Boolean)
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
plugins,
|
|
113
|
+
|
|
114
|
+
build: {
|
|
115
|
+
lib: {
|
|
116
|
+
entry: resolve(foundationRoot, entry),
|
|
117
|
+
formats: ['es'],
|
|
118
|
+
fileName
|
|
119
|
+
},
|
|
120
|
+
rollupOptions: {
|
|
121
|
+
external: externals,
|
|
122
|
+
output: {
|
|
123
|
+
assetFileNames: 'assets/[name][extname]'
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
sourcemap,
|
|
127
|
+
cssCodeSplit: false,
|
|
128
|
+
...buildOverrides
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
...restOptions
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Default export - an async function that can be used directly as vite.config.js
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* // vite.config.js - simplest form
|
|
140
|
+
* export { default } from '@uniweb/build/foundation/config'
|
|
141
|
+
*/
|
|
142
|
+
export default function (overrides = {}) {
|
|
143
|
+
return defineFoundationConfig(overrides)
|
|
144
|
+
}
|
package/src/index.js
CHANGED
|
@@ -46,5 +46,11 @@ export {
|
|
|
46
46
|
generateDocsFromSchema,
|
|
47
47
|
} from './docs.js'
|
|
48
48
|
|
|
49
|
+
// Foundation config
|
|
50
|
+
export { defineFoundationConfig } from './foundation/config.js'
|
|
51
|
+
|
|
52
|
+
// Site config
|
|
53
|
+
export { defineSiteConfig } from './site/config.js'
|
|
54
|
+
|
|
49
55
|
// Default export is the combined Vite plugin
|
|
50
56
|
export { default } from './vite-foundation-plugin.js'
|