-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
chore: Update local and Vercel preview. Fix CSS watch functionality. #2348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f339967
Remove HTML build
jhildenbiddle f453f4b
Fix CSS watch script
jhildenbiddle 04bd732
Add Vercal configuration
jhildenbiddle 1b9d200
Tem fix for Vercal “unsupported modules:” error
jhildenbiddle 5a0a289
Update server start console message
jhildenbiddle 208ddbb
Fix for Vercal “unsupported modules” error
jhildenbiddle 8f7f57f
Fix for Vercal “unsupported modules” error
jhildenbiddle f0b47ec
Fix for Vercal “unsupported modules” error
jhildenbiddle 47656e1
Fix for Vercal “unsupported modules” error
jhildenbiddle 8e1adec
Switch to named server config exports
jhildenbiddle 8d06856
Serve Vercel preview from root
jhildenbiddle 0c2d237
Revert "Serve Vercel preview from root"
jhildenbiddle acd69cd
Fix console output
jhildenbiddle 6b35b7b
Merge branch 'develop' into vercel-preview-update
Koooooo-7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Exports | ||
// ============================================================================= | ||
export const config = { | ||
matcher: ['/preview/(index.html)?'], | ||
}; | ||
|
||
// Rewrite rules shared with local server configurations | ||
export const rewriteRules = [ | ||
// Replace CDN URLs with local paths | ||
{ | ||
match: /https?.*\/CHANGELOG.md/g, | ||
replace: '/CHANGELOG.md', | ||
}, | ||
{ | ||
// CDN versioned default | ||
// Ex1: //cdn.com/package-name | ||
// Ex2: http://cdn.com/[email protected] | ||
// Ex3: https://cdn.com/package-name@latest | ||
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*(?=["'])/g, | ||
replace: '/lib/docsify.min.js', | ||
}, | ||
{ | ||
// CDN paths to local paths | ||
// Ex1: //cdn.com/package-name/path/file.js => /path/file.js | ||
// Ex2: http://cdn.com/[email protected]/dist/file.js => /dist/file.js | ||
// Ex3: https://cdn.com/package-name@latest/dist/file.js => /dist/file.js | ||
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*\/(?:lib\/)/g, | ||
replace: '/lib/', | ||
}, | ||
]; | ||
|
||
// Serve virtual /preview/index.html | ||
// Note: See vercel.json for preview routing configuration | ||
// 1. Fetch index.html from /docs/ directory | ||
// 2. Replace CDN URLs with local paths (see rewriteRules) | ||
// 3. Return preview HTML | ||
export default async function middleware(request) { | ||
const { origin } = new URL(request.url); | ||
const indexURL = `${origin}/docs/index.html`; | ||
const indexHTML = await fetch(indexURL).then(res => res.text()); | ||
const previewHTML = rewriteRules.reduce( | ||
(html, rule) => html.replace(rule.match, rule.replace), | ||
indexHTML | ||
); | ||
|
||
return new Response(previewHTML, { | ||
status: 200, | ||
headers: { | ||
'content-type': 'text/html', | ||
'x-robots-tag': 'noindex', | ||
}, | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import { create } from 'browser-sync'; | ||
import serverConfigs from './server.config.js'; | ||
import { devConfig, prodConfig } from './server.configs.js'; | ||
|
||
const bsServer = create(); | ||
const args = process.argv.slice(2); | ||
const configName = | ||
Object.keys(serverConfigs).find(name => args.includes(`--${name}`)) || 'prod'; | ||
const settings = serverConfigs[configName]; | ||
const config = args.includes('--dev') ? devConfig : prodConfig; | ||
const configName = config === devConfig ? 'development' : 'production'; | ||
const isWatch = Boolean(config.files) && config.watch !== false; | ||
const urlType = config === devConfig ? 'local' : 'CDN'; | ||
|
||
// prettier-ignore | ||
console.log(`\nStarting ${configName} server (${settings.server.index}, watch: ${Boolean(settings.files)})\n`); | ||
console.log(`\nStarting ${configName} server (${urlType} URLs, watch: ${isWatch})\n`); | ||
|
||
bsServer.init(settings); | ||
bsServer.init(config); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
{ | ||
"redirects": [ | ||
"headers": [ | ||
{ | ||
"source": "/", | ||
"destination": "./docs/preview.html", | ||
"permanent": true | ||
"source": "/(.*)", | ||
"headers": [{ "key": "x-robots-tag", "value": "noindex" }] | ||
} | ||
], | ||
"redirects": [{ "source": "/", "destination": "/preview/" }], | ||
"rewrites": [ | ||
{ "source": "/preview/CHANGELOG.md", "destination": "/CHANGELOG.md" }, | ||
{ "source": "/preview/:path*", "destination": "/docs/:path*" } | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.