Skip to content

Commit 4f44d47

Browse files
authored
feat: use vercel deploy production (conwnet#191)
1 parent 597a99a commit 4f44d47

5 files changed

Lines changed: 23 additions & 51 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"clean-build": "./scripts/clean-build.sh",
3030
"clean": "./scripts/clean.sh",
3131
"build": "./scripts/build.sh",
32-
"vercel-build": "yarn build && mv dist public",
32+
"vercel-build": "yarn build && yarn hash && mv dist public",
3333
"hash": "./scripts/hash.sh",
3434
"package": "./scripts/package.sh",
3535
"watch": "rm -rf dist && run-p watch:*",

resources/index-hash.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ <h1>You need to enable JavaScript to run this app.</h1>
133133

134134
<script>
135135
self.require = {
136-
baseUrl: `${window.location.origin}/{STATIC_FOLDER}/vscode`,
136+
baseUrl: `${window.location.origin}/static/{STATIC_HASH_CODE}/vscode`,
137137
recordStats: true,
138138
trustedTypesPolicy: window.trustedTypes?.createPolicy('amdLoader', {
139139
createScriptURL(value) {
@@ -144,25 +144,25 @@ <h1>You need to enable JavaScript to run this app.</h1>
144144
},
145145
}),
146146
paths: {
147-
'vscode-textmate': `${window.location.origin}/{STATIC_FOLDER}/node_modules/vscode-textmate/release/main`,
148-
'vscode-oniguruma': `${window.location.origin}/{STATIC_FOLDER}/node_modules/vscode-oniguruma/release/main`,
149-
xterm: `${window.location.origin}/{STATIC_FOLDER}/node_modules/xterm/lib/xterm.js`,
150-
'xterm-addon-search': `${window.location.origin}/{STATIC_FOLDER}/node_modules/xterm-addon-search/lib/xterm-addon-search.js`,
151-
'xterm-addon-unicode11': `${window.location.origin}/{STATIC_FOLDER}/node_modules/xterm-addon-unicode11/lib/xterm-addon-unicode11.js`,
152-
'xterm-addon-webgl': `${window.location.origin}/{STATIC_FOLDER}/node_modules/xterm-addon-webgl/lib/xterm-addon-webgl.js`,
153-
'tas-client-umd': `${window.location.origin}/{STATIC_FOLDER}/node_modules/tas-client-umd/lib/tas-client-umd.js`,
154-
'iconv-lite-umd': `${window.location.origin}/{STATIC_FOLDER}/node_modules/iconv-lite-umd/lib/iconv-lite-umd.js`,
155-
jschardet: `${window.location.origin}/{STATIC_FOLDER}/node_modules/jschardet/dist/jschardet.min.js`,
147+
'vscode-textmate': `${window.location.origin}/static/{STATIC_HASH_CODE}/node_modules/vscode-textmate/release/main`,
148+
'vscode-oniguruma': `${window.location.origin}/static/{STATIC_HASH_CODE}/node_modules/vscode-oniguruma/release/main`,
149+
xterm: `${window.location.origin}/static/{STATIC_HASH_CODE}/node_modules/xterm/lib/xterm.js`,
150+
'xterm-addon-search': `${window.location.origin}/static/{STATIC_HASH_CODE}/node_modules/xterm-addon-search/lib/xterm-addon-search.js`,
151+
'xterm-addon-unicode11': `${window.location.origin}/static/{STATIC_HASH_CODE}/node_modules/xterm-addon-unicode11/lib/xterm-addon-unicode11.js`,
152+
'xterm-addon-webgl': `${window.location.origin}/static/{STATIC_HASH_CODE}/node_modules/xterm-addon-webgl/lib/xterm-addon-webgl.js`,
153+
'tas-client-umd': `${window.location.origin}/static/{STATIC_HASH_CODE}/node_modules/tas-client-umd/lib/tas-client-umd.js`,
154+
'iconv-lite-umd': `${window.location.origin}/static/{STATIC_HASH_CODE}/node_modules/iconv-lite-umd/lib/iconv-lite-umd.js`,
155+
jschardet: `${window.location.origin}/static/{STATIC_HASH_CODE}/node_modules/jschardet/dist/jschardet.min.js`,
156156
},
157157
};
158158
</script>
159-
<script src="/{STATIC_FOLDER}/vscode/vs/loader.js"></script>
160-
<script src="/{STATIC_FOLDER}/vscode/vs/workbench/workbench.web.api.js"></script>
159+
<script src="/static/{STATIC_HASH_CODE}/vscode/vs/loader.js"></script>
160+
<script src="/static/{STATIC_HASH_CODE}/vscode/vs/workbench/workbench.web.api.js"></script>
161161
<script>
162162
globalThis.MonacoPerformanceMarks.push('willLoadWorkbenchMain', Date.now());
163163
</script>
164164
<script>
165-
fetch('/{STATIC_FOLDER}/configure/extensions.json')
165+
fetch('/static/{STATIC_HASH_CODE}/configure/extensions.json')
166166
.then((response) => response.text())
167167
.then((extensionsJson) => {
168168
document
@@ -176,9 +176,9 @@ <h1>You need to enable JavaScript to run this app.</h1>
176176
enableSyncByDefault: false,
177177
webviewEndpoint:
178178
window.location.origin +
179-
'/{STATIC_FOLDER}/vscode/vs/workbench/contrib/webview/browser/pre',
179+
'/static/{STATIC_HASH_CODE}/vscode/vs/workbench/contrib/webview/browser/pre',
180180
webWorkerExtensionHostIframeSrc:
181-
'/{STATIC_FOLDER}/vscode/vs/workbench/services/extensions/worker/httpWebWorkerExtensionHostIframe.html',
181+
'/static/{STATIC_HASH_CODE}/vscode/vs/workbench/services/extensions/worker/httpWebWorkerExtensionHostIframe.html',
182182
})
183183
);
184184
document

scripts/hash.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ APP_ROOT=$(pwd)
66

77
COMMIT_ID=$(git rev-parse HEAD)
88
SHORT_COMMIT_ID=${COMMIT_ID:0:7}
9-
STATIC_FOLDER_NAME="static-${SHORT_COMMIT_ID-unknown}"
9+
STATIC_HASH_CODE="${SHORT_COMMIT_ID-unknown}"
1010

1111
if [ -e "${APP_ROOT}/dist/static" ]; then
12-
mv "${APP_ROOT}/dist/static" "${APP_ROOT}/dist/${STATIC_FOLDER_NAME}"
13-
sed "s/{STATIC_FOLDER}/${STATIC_FOLDER_NAME}/" "${APP_ROOT}/resources/index-hash.html" > "${APP_ROOT}/dist/404.html"
14-
rm -f "${APP_ROOT}/dist/index.html" # remove the exists `index.html` file
12+
mv "${APP_ROOT}/dist/static" "${APP_ROOT}/dist/${STATIC_HASH_CODE}"
13+
mkdir -p "${APP_ROOT}/dist/static"
14+
mv "${APP_ROOT}/dist/${STATIC_HASH_CODE}" "${APP_ROOT}/dist/static/${STATIC_HASH_CODE}"
15+
sed "s/{STATIC_HASH_CODE}/${STATIC_HASH_CODE}/" "${APP_ROOT}/resources/index-hash.html" > "${APP_ROOT}/dist/index.html"
1516
echo "hash static files done"
1617
else
1718
echo "Please build github1s first"

vercel.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"routes": [{
33
"src": "/static/(.*)",
4-
"dest": "/images/$1"
4+
"dest": "/static/$1",
5+
"headers": { "Cache-Control": "max-age=604800" }
56
},
67
{
78
"src": "/favicon.ico",

0 commit comments

Comments
 (0)