Skip to content
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

refactor(index.html): update DNS prefetch domains to *.gopluscdn.com #928

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor(index.html): update DNS prefetch domains to *.gopluscdn.com
Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
  • Loading branch information
aofei committed Sep 24, 2024
commit 12bb60758dffeb0765803391422b3a5d60b2d197
16 changes: 12 additions & 4 deletions spx-gui/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="dns-prefetch" href="https://builder-static.goplus.org" />
<link rel="dns-prefetch" href="https://aigc-static.goplus.org" />
<link rel="dns-prefetch" href="https://upload-na0.qiniup.com" />
<link rel="preconnect" href="https://builder-static.goplus.org" crossorigin />
<% if (NODE_ENV === 'production') { %>
<link rel="dns-prefetch" href="https://builder-static.gopluscdn.com" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我想起来部署到测试环境时,NODE_ENV 应该也是 production..

https://vitejs.dev/guide/env-and-mode.html#node-env-and-modes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好吧,那其实 vite.config.ts 里的 mode 也是有点小问题的,应该也同样一直是 production

const env = loadEnv(mode, process.cwd(), '')


现在应该有两种解决办法,一种是再提供一个类似 buildbuild-dev script,区别是它会设置 NODE_ENV--mode development
另一种是在 .github/workflows/build.yml 里加上 echo "NODE_ENV=development" >> .env

第二种可能简单些,但是按 https://vitejs.dev/guide/env-and-mode.html#node-env-and-modes 里的意思更推荐第一种?

NODE_ENV in .env files
NODE_ENV=... can be set in the command, and also in your .env file. If NODE_ENV is specified in a .env.[mode] file, the mode can be used to control its value. However, both NODE_ENV and modes remain as two different concepts.

The main benefit with NODE_ENV=... in the command is that it allows Vite to detect the value early. It also allows you to read process.env.NODE_ENV in your Vite config as Vite can only load the env files once the config is evaluated.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好吧,那其实 vite.config.ts 里的 mode 也是有点小问题的,应该也同样一直是 production

嗯,从充分利用 vite 的能力来说是的,我之前都没注意它还能这样自动 load 不同的 env 文件..

第二种可能简单些,但是按 https://vitejs.dev/guide/env-and-mode.html#node-env-and-modes 里的意思更推荐第一种?

我也倾向第一种,之前在 .github/workflows/build.yml 里 echo 的做法总感觉怪怪的;用第一种的做法的话,我们就可以把测试环境的 env 文件也直接提交在 spx-gui/ 下,比在 .github/workflows/build.yml 里维护会好一点

不过是不是 build-staging 要比 build-dev 合适一点?我理解我们本地开发时才是 mode: dev,我们部署的测试环境更接近 mode: staging?

NODE_ENV=development vite build --mode development

另外我不确定这里的 NODE_ENV & mode 会不会影响 vite build 本身的行为,以前用 webpack 的时候,如果 env 不是 production 就可能不做类似 compression 这种优化;我们预期应该是 staging 跟 production 的 vite 行为完全一致,只是那个配置、环境变量值不同

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另外我不确定这里的 NODE_ENV & mode 会不会影响 vite build 本身的行为

又看了一遍文档,没提,应该是不会影响

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

细节还不少,所以单独开了个 issue 追一下这个问题 #929

<link rel="dns-prefetch" href="https://builder-usercontent.gopluscdn.com" />
<link rel="preconnect" href="https://builder-static.gopluscdn.com" crossorigin />
<link rel="preconnect" href="https://builder-usercontent.gopluscdn.com" crossorigin />
<% } else { %>
<link rel="dns-prefetch" href="https://builder-static-test.gopluscdn.com" />
<link rel="dns-prefetch" href="https://builder-usercontent-test.gopluscdn.com" />
<link rel="preconnect" href="https://builder-static-test.gopluscdn.com" crossorigin />
<link rel="preconnect" href="https://builder-usercontent-test.gopluscdn.com" crossorigin />
<% } %>

<title>Go+ Builder</title>
<meta name="description" content="Go+ Builder is a tool for building games. We create it to help children to learn abilities to build." />
Expand Down
222 changes: 214 additions & 8 deletions spx-gui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions spx-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"ts-node": "^10.9.1",
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vite-plugin-ejs": "^1.7.0",
"vite-plugin-top-level-await": "^1.4.1",
"vite-plugin-vercel": "^9.0.1",
"vite-plugin-vue-devtools": "^7.0.7",
Expand Down
3 changes: 2 additions & 1 deletion spx-gui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import VueDevTools from 'vite-plugin-vue-devtools'
import { ViteEjsPlugin } from 'vite-plugin-ejs'
import vercel from 'vite-plugin-vercel'
import path from 'path'
// https://vitejs.dev/config/
const resolve = (dir: string) => path.join(__dirname, dir)
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
return {
plugins: [vue(), VueDevTools(), vercel()],
plugins: [vue(), VueDevTools(), ViteEjsPlugin(), vercel()],
resolve: {
alias: {
'@': resolve('src')
Expand Down
Loading