mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-19 20:09:35 +00:00
chore(examples): update routify version to 2.x
This commit is contained in:
parent
251f986304
commit
1fdd2338f9
32 changed files with 2849 additions and 2693 deletions
16
examples/routify/api/netlify/package.json
Normal file
16
examples/routify/api/netlify/package.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "ssr",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "ssr.js",
|
||||
"scripts": {
|
||||
"build": "node utils/build.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"esbuild": "^0.8.8",
|
||||
"tossr": "^1.3.1"
|
||||
}
|
||||
}
|
11
examples/routify/api/netlify/ssr.js
Normal file
11
examples/routify/api/netlify/ssr.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const fs = require('fs')
|
||||
const { tossr } = require('tossr')
|
||||
const { script, template } = require('./bundle.json')
|
||||
|
||||
exports.handler = async (event, context) => {
|
||||
const qs = Object.entries(event.queryStringParameters)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join('&');
|
||||
const body = await tossr(template, script, `${event.path}?${qs}`);
|
||||
return { statusCode: 200, body: body + '\n<!--ssr rendered-->' }
|
||||
}
|
26
examples/routify/api/netlify/utils/build.js
Normal file
26
examples/routify/api/netlify/utils/build.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Creates a JSON and inlines it with esbuild for ssr.js to consume
|
||||
* {
|
||||
* data: duh,
|
||||
* script: inlined main.js
|
||||
* template: __app.html
|
||||
* }
|
||||
*/
|
||||
|
||||
const { resolve } = require('path')
|
||||
const { readFileSync, writeFileSync } = require('fs')
|
||||
const { build } = require('esbuild')
|
||||
|
||||
const scriptPath = resolve(__dirname, '../../../dist/build/main.js')
|
||||
const templatePath = resolve(__dirname, '../../../dist/__app.html')
|
||||
const bundlePath = resolve(__dirname, '../build/bundle.js')
|
||||
|
||||
build({ entryPoints: [scriptPath], outfile: bundlePath, bundle: true }).then(() => {
|
||||
const bundle = {
|
||||
date: new Date,
|
||||
script: readFileSync(bundlePath, 'utf8'),
|
||||
template: readFileSync(templatePath, 'utf8')
|
||||
}
|
||||
|
||||
writeFileSync(resolve(__dirname, '../bundle.json'), JSON.stringify(bundle, null, 2))
|
||||
})
|
36
examples/routify/api/vercel-ssr/build.js
Normal file
36
examples/routify/api/vercel-ssr/build.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
const { resolve } = require('path')
|
||||
const { existsSync } = require('fs')
|
||||
const { execSync } = require('child_process')
|
||||
const { rollup } = require('rollup')
|
||||
|
||||
const shouldBuildSpa = process.env.NOW_GITHUB_DEPLOYMENT || process.env.NOW_BUILDER
|
||||
const script = resolve(__dirname, '../../dist/build/main.js')
|
||||
const bundlePath = resolve(__dirname, '../../dist/build/bundle.js')
|
||||
|
||||
build()
|
||||
|
||||
|
||||
async function build() {
|
||||
if (shouldBuildSpa)
|
||||
execSync('npm install && npm run build:app', { cwd: resolve('..', '..'), stdio: 'inherit' })
|
||||
else
|
||||
await waitForAppToExist()
|
||||
|
||||
buildSSRBundle()
|
||||
}
|
||||
|
||||
async function waitForAppToExist() {
|
||||
while (!existsSync(script)) {
|
||||
console.log(`checking if "${script}" exists`)
|
||||
await new Promise(r => setTimeout(r, 2000))
|
||||
}
|
||||
console.log(`found "${script}"`)
|
||||
}
|
||||
|
||||
async function buildSSRBundle() {
|
||||
const bundle = await rollup({
|
||||
input: script,
|
||||
inlineDynamicImports: true,
|
||||
})
|
||||
await bundle.write({ format: 'umd', file: bundlePath, name: 'roxi-ssr' })
|
||||
}
|
11
examples/routify/api/vercel-ssr/index.js
Normal file
11
examples/routify/api/vercel-ssr/index.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const fs = require('fs')
|
||||
const { tossr } = require('tossr')
|
||||
|
||||
const script = fs.readFileSync(require.resolve('../../dist/build/bundle.js'), 'utf8')
|
||||
const template = fs.readFileSync(require.resolve('../../dist/__app.html'), 'utf8')
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const html = await tossr(template, script, req.url, {})
|
||||
res.send(html + '\n<!--ssr rendered-->')
|
||||
}
|
||||
|
8
examples/routify/api/vercel-ssr/package.json
Normal file
8
examples/routify/api/vercel-ssr/package.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"scripts": {
|
||||
"vercel-build": "node ./build.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rollup": "^2.28.2"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue