该帖子系列已在 ngatesystems.com 上建立索引。您还可以在那里找到超级有用的关键字搜索工具。
最后评论:24 年 11 月
post 4.2 提出了预渲染网页的概念。这个想法是,如果一个页面从不改变(或者至少不经常改变),那么它也可能在项目的“构建”过程中被转换成 html。
这很好,但是,如果底层数据更改得太频繁,运行构建来使预渲染页面保持最新手动将会变得烦人。 自动化肯定是答案。
您可以通过多种方式解决这个问题,但我建议使用脚本来运行构建/部署序列,然后让 windows 调度程序自动运行它
这是您可能会使用的 ps1 脚本:
$projectId = [myProjectId] $projectPath = [myProjectPath] # Define log file path $logPath = "$projectPath\log.txt" # Overwrite the log file with a timestamp at the beginning $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" "Log started at $timestamp" | Out-File -FilePath $logPath -Force # Set the project ID gcloud config set project $projectId # Redirect output to log file try { cd $projectPath 2>&1 | Out-File -FilePath $logPath -Append npm run build | Out-File -FilePath $logPath -Append # Fetch all versions ordered by creation date, excluding the latest 10 $oldVersions = gcloud app versions list ` --sort-by="~version.createTime" ` --format="value(version.id)" | Select-Object -Skip 10 # Delete the old versions if there are any if ($oldVersions.Count -gt 0) { "Deleting old versions..."| Out-File -FilePath $logPath -Force $oldVersions | ForEach-Object { gcloud app versions delete $_ --quiet 2>&1 | Out-File -FilePath $logPath -Append } } else { "No old versions to delete. The limit of $MaxVersions is not exceeded." | Out-File -FilePath $logPath -Force } gcloud app deploy build/app.yaml --quiet 2>&1 | Out-File -FilePath $logPath -Append } catch { "An error occurred: $_" | Out-File -FilePath $logPath -Append }
在此脚本中,[myprojectid} 是您的 google 项目 id - 例如“svelte-dev-80286”
[myprojectpath] 是 vscode 项目的完整路径名 - 例如“c:usersmjoycdesktopgitprojectssvelte-dev”。输出 log.txt 文件最终位于 vscode 项目文件夹的根目录
脚本看起来比你想象的更复杂。原因如下:
因为您打算自动调度脚本,所以您需要维护一个日志文件,以便在出现错误时告诉您出了什么问题。仅此一点就增加了许多不可避免的“混乱”。但还有一个奇怪的“版本删除”部分。您需要这个,因为每次您运行“构建”时,google 都会在云存储中创建一个新版本。您可以创建的版本数量有默认上限。当我的系统在版本数达到 200 时出错时,我添加了此部分。
在上面的脚本中,我将维护的版本数量限制为 10 个(我现在正在为我的应用程序运行托管付费!)。
在 vscode 终端会话中测试脚本文件的最直接方法是选择其内容,将其粘贴到会话中并按回车键。但出于生产目的,您需要一些自动化。
以下是注册 windows scheduler 任务以运行构建脚本的过程。
我使用通过上述过程创建的 windows scheduler 任务来为预渲染的“ngatesystems.com”关键字搜索页面运行夜间构建。尽管现在很少添加新帖子,但我仍在对现有页面进行定期编辑。每晚运行的安排意味着搜索页面永远不会落后于实时数据超过一天。
以上就是NgSysVAutomated Svelte Pre-render Builds的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号