uniweb 0.2.9 → 0.2.10
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 +3 -3
- package/package.json +2 -2
- package/src/commands/build.js +54 -2
- package/src/index.js +12 -7
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ my-project/
|
|
|
46
46
|
|
|
47
47
|
```markdown
|
|
48
48
|
---
|
|
49
|
-
|
|
49
|
+
type: Hero
|
|
50
50
|
theme: dark
|
|
51
51
|
---
|
|
52
52
|
|
|
@@ -57,7 +57,7 @@ Build something great.
|
|
|
57
57
|
[Get Started](#)
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
Frontmatter specifies the component and configuration. The body contains the actual content—headings, paragraphs, links, images—which gets semantically parsed into structured data your component receives.
|
|
60
|
+
Frontmatter specifies the component type and configuration. The body contains the actual content—headings, paragraphs, links, images—which gets semantically parsed into structured data your component receives.
|
|
61
61
|
|
|
62
62
|
### Beyond Markdown
|
|
63
63
|
|
|
@@ -459,7 +459,7 @@ Pages can define data sources that auto-generate subroutes. A `/blog` page can h
|
|
|
459
459
|
## Related Packages
|
|
460
460
|
|
|
461
461
|
- [`@uniweb/build`](https://github.com/uniweb/build) — Foundation build tooling
|
|
462
|
-
- [`@uniweb/runtime`](https://github.com/uniweb/runtime) —
|
|
462
|
+
- [`@uniweb/runtime`](https://github.com/uniweb/runtime) — Foundation loader and orchestrator for sites
|
|
463
463
|
- [`@uniweb/templates`](https://github.com/uniweb/templates) — Official templates and template processing
|
|
464
464
|
|
|
465
465
|
## License
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uniweb",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Create structured Vite + React sites with content/code separation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"@uniweb/build": "^0.1.0",
|
|
35
35
|
"prompts": "^2.4.2",
|
|
36
36
|
"tar": "^7.0.0",
|
|
37
|
-
"@uniweb/templates": "0.1.
|
|
37
|
+
"@uniweb/templates": "0.1.6"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/src/commands/build.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* uniweb build # Build current directory
|
|
8
8
|
* uniweb build --target foundation # Explicitly build as foundation
|
|
9
9
|
* uniweb build --target site # Explicitly build as site
|
|
10
|
+
* uniweb build --prerender # Build site + pre-render to static HTML (SSG)
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
13
|
import { existsSync } from 'node:fs'
|
|
@@ -181,12 +182,47 @@ async function buildFoundation(projectDir, options = {}) {
|
|
|
181
182
|
* Build a site
|
|
182
183
|
*/
|
|
183
184
|
async function buildSite(projectDir, options = {}) {
|
|
185
|
+
const { prerender = false, foundationDir } = options
|
|
186
|
+
|
|
184
187
|
info('Building site...')
|
|
185
188
|
|
|
186
|
-
//
|
|
189
|
+
// Run vite build for sites
|
|
187
190
|
await runCommand('npx', ['vite', 'build'], projectDir)
|
|
188
191
|
|
|
189
192
|
success('Site build complete')
|
|
193
|
+
|
|
194
|
+
// Pre-render if requested
|
|
195
|
+
if (prerender) {
|
|
196
|
+
log('')
|
|
197
|
+
info('Pre-rendering pages to static HTML (SSG)...')
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
const { prerenderSite } = await import('@uniweb/build/prerender')
|
|
201
|
+
|
|
202
|
+
const result = await prerenderSite(projectDir, {
|
|
203
|
+
foundationDir: foundationDir || join(projectDir, '..', 'foundation'),
|
|
204
|
+
onProgress: (msg) => log(` ${colors.dim}${msg}${colors.reset}`)
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
success(`Pre-rendered ${result.pages} page${result.pages !== 1 ? 's' : ''} to static HTML`)
|
|
208
|
+
|
|
209
|
+
// Summary
|
|
210
|
+
log('')
|
|
211
|
+
log(`${colors.green}${colors.bright}SSG Build complete!${colors.reset}`)
|
|
212
|
+
log('')
|
|
213
|
+
log(`Output:`)
|
|
214
|
+
for (const file of result.files) {
|
|
215
|
+
const relativePath = file.replace(projectDir + '/', '')
|
|
216
|
+
log(` ${colors.dim}${relativePath}${colors.reset}`)
|
|
217
|
+
}
|
|
218
|
+
} catch (err) {
|
|
219
|
+
error(`Pre-rendering failed: ${err.message}`)
|
|
220
|
+
if (process.env.DEBUG) {
|
|
221
|
+
console.error(err.stack)
|
|
222
|
+
}
|
|
223
|
+
process.exit(1)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
190
226
|
}
|
|
191
227
|
|
|
192
228
|
/**
|
|
@@ -207,6 +243,16 @@ export async function build(args = []) {
|
|
|
207
243
|
}
|
|
208
244
|
}
|
|
209
245
|
|
|
246
|
+
// Check for --prerender flag (SSG)
|
|
247
|
+
const prerender = args.includes('--prerender')
|
|
248
|
+
|
|
249
|
+
// Check for --foundation-dir flag (for prerendering)
|
|
250
|
+
let foundationDir = null
|
|
251
|
+
const foundationDirIndex = args.indexOf('--foundation-dir')
|
|
252
|
+
if (foundationDirIndex !== -1 && args[foundationDirIndex + 1]) {
|
|
253
|
+
foundationDir = resolve(args[foundationDirIndex + 1])
|
|
254
|
+
}
|
|
255
|
+
|
|
210
256
|
// Auto-detect project type if not specified
|
|
211
257
|
if (!targetType) {
|
|
212
258
|
targetType = detectProjectType(projectDir)
|
|
@@ -220,12 +266,18 @@ export async function build(args = []) {
|
|
|
220
266
|
info(`Detected project type: ${targetType}`)
|
|
221
267
|
}
|
|
222
268
|
|
|
269
|
+
// Validate prerender is only used with site target
|
|
270
|
+
if (prerender && targetType !== 'site') {
|
|
271
|
+
error('--prerender can only be used with site builds')
|
|
272
|
+
process.exit(1)
|
|
273
|
+
}
|
|
274
|
+
|
|
223
275
|
// Run appropriate build
|
|
224
276
|
try {
|
|
225
277
|
if (targetType === 'foundation') {
|
|
226
278
|
await buildFoundation(projectDir)
|
|
227
279
|
} else {
|
|
228
|
-
await buildSite(projectDir)
|
|
280
|
+
await buildSite(projectDir, { prerender, foundationDir })
|
|
229
281
|
}
|
|
230
282
|
} catch (err) {
|
|
231
283
|
error(err.message)
|
package/src/index.js
CHANGED
|
@@ -226,6 +226,8 @@ ${colors.bright}Create Options:${colors.reset}
|
|
|
226
226
|
|
|
227
227
|
${colors.bright}Build Options:${colors.reset}
|
|
228
228
|
--target <type> Build target (foundation, site) - auto-detected if not specified
|
|
229
|
+
--prerender Pre-render pages to static HTML (SSG) - site builds only
|
|
230
|
+
--foundation-dir Path to foundation directory (for prerendering)
|
|
229
231
|
--platform <name> Deployment platform (e.g., vercel) for platform-specific output
|
|
230
232
|
|
|
231
233
|
${colors.bright}Template Types:${colors.reset}
|
|
@@ -243,6 +245,7 @@ ${colors.bright}Examples:${colors.reset}
|
|
|
243
245
|
npx uniweb create my-project --template github:myorg/template
|
|
244
246
|
npx uniweb build
|
|
245
247
|
npx uniweb build --target foundation
|
|
248
|
+
npx uniweb build --prerender # Build site + pre-render to static HTML
|
|
246
249
|
`)
|
|
247
250
|
}
|
|
248
251
|
|
|
@@ -384,7 +387,7 @@ Each markdown file specifies which component to use:
|
|
|
384
387
|
|
|
385
388
|
\`\`\`markdown
|
|
386
389
|
---
|
|
387
|
-
|
|
390
|
+
type: Hero
|
|
388
391
|
theme: dark
|
|
389
392
|
---
|
|
390
393
|
|
|
@@ -601,13 +604,14 @@ async function createSite(projectDir, projectName, isWorkspace = false) {
|
|
|
601
604
|
...(isWorkspace ? {} : { 'foundation-example': '^0.1.0' }),
|
|
602
605
|
},
|
|
603
606
|
devDependencies: {
|
|
607
|
+
'@uniweb/build': '^0.1.3',
|
|
604
608
|
'@vitejs/plugin-react': '^5.0.0',
|
|
605
609
|
autoprefixer: '^10.4.18',
|
|
606
610
|
'js-yaml': '^4.1.0',
|
|
607
611
|
postcss: '^8.4.35',
|
|
608
612
|
react: '^18.2.0',
|
|
609
613
|
'react-dom': '^18.2.0',
|
|
610
|
-
'react-router-dom': '^
|
|
614
|
+
'react-router-dom': '^7.0.0',
|
|
611
615
|
tailwindcss: '^3.4.1',
|
|
612
616
|
vite: '^7.0.0',
|
|
613
617
|
'vite-plugin-svgr': '^4.2.0',
|
|
@@ -659,7 +663,8 @@ import { readFileSync, existsSync } from 'fs'
|
|
|
659
663
|
import yaml from 'js-yaml'
|
|
660
664
|
import react from '@vitejs/plugin-react'
|
|
661
665
|
import svgr from 'vite-plugin-svgr'
|
|
662
|
-
import { siteContentPlugin
|
|
666
|
+
import { siteContentPlugin } from '@uniweb/build/site'
|
|
667
|
+
import { foundationDevPlugin } from '@uniweb/build/dev'
|
|
663
668
|
|
|
664
669
|
// Read foundation from site.yml
|
|
665
670
|
const siteConfig = yaml.load(readFileSync('./site.yml', 'utf8'))
|
|
@@ -685,7 +690,7 @@ export default defineConfig({
|
|
|
685
690
|
sitePath: './',
|
|
686
691
|
inject: true,
|
|
687
692
|
}),
|
|
688
|
-
useRuntimeLoading &&
|
|
693
|
+
useRuntimeLoading && foundationDevPlugin({
|
|
689
694
|
name: foundation,
|
|
690
695
|
path: foundationPath,
|
|
691
696
|
serve: '/foundation',
|
|
@@ -724,7 +729,7 @@ export default defineConfig({
|
|
|
724
729
|
`)
|
|
725
730
|
|
|
726
731
|
// main.jsx - uses #foundation alias (configured in vite.config.js from site.yml)
|
|
727
|
-
writeFile(join(projectDir, 'src/main.jsx'), `import
|
|
732
|
+
writeFile(join(projectDir, 'src/main.jsx'), `import initRuntime from '@uniweb/runtime'
|
|
728
733
|
|
|
729
734
|
const useRuntimeLoading = import.meta.env.VITE_FOUNDATION_MODE === 'runtime'
|
|
730
735
|
|
|
@@ -760,7 +765,7 @@ order: 1
|
|
|
760
765
|
|
|
761
766
|
// pages/home/1-hero.md
|
|
762
767
|
writeFile(join(projectDir, 'pages/home/1-hero.md'), `---
|
|
763
|
-
|
|
768
|
+
type: Hero
|
|
764
769
|
theme: dark
|
|
765
770
|
---
|
|
766
771
|
|
|
@@ -815,7 +820,7 @@ order: 2
|
|
|
815
820
|
|
|
816
821
|
\`\`\`markdown
|
|
817
822
|
---
|
|
818
|
-
|
|
823
|
+
type: Hero
|
|
819
824
|
theme: dark
|
|
820
825
|
---
|
|
821
826
|
|