成为我们的资助者或赞助商,以支持我们的工作。
这篇文章包含了如何在 Netlify 上部署网站的分步说明。
可以通过多种方式于 Netlify 部署站点,本文只对基于文件配置的部署方式,其比控制台设置更灵活。
首先创建以下配置文件,然后提交到你的仓库。
1[build]
2command = """
3DART_SASS_VERSION="${DART_SASS_VERSION:-1.79.5}" && \
4curl -LJO https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz && \
5tar -xf dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz && rm dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz && \
6export PATH=/opt/build/repo/dart-sass:$PATH && \
7npm ci && \
8hugo --minify -b $URL
9"""
10publish = "public"
11
12[build.environment]
13NODE_VERSION = "19"
14HUGO_VERSION = "0.121.2"
15HUGO_ENABLEGITINFO = "true"
16HUGO_ENV = "production"
17GO_VERSION = "1.20"
18
19[[headers]]
20 for = "/*"
21 [headers.values]
22 Referrer-Policy = "strict-origin-when-cross-origin"
23 X-Content-Type-Options = "nosniff"
24 X-Frame-Options = "deny"
25 X-XSS-Protection = "1; mode=block"
26
27# multilingual 404 pages, remove it on monolingual sites.
28[[redirects]]
29 from = "/en/*"
30 to = "/en/404.html"
31 status = 404
32
33[[redirects]]
34 from = "/zh-hans/*"
35 to = "/zh-hans/404.html"
36 status = 404
37
38# fallback 404 page.
39[[redirects]]
40 from = "/*"
41 to = "/404.html"
42 # to = "/en/404.html" # use this instead if defaultContentLanguageInSubdir is enabled.
43 status = 404
注意
Dart Sass 默认版本为
-1.79.5
,可通过指定DART_SASS_VERSION
环境变量来修改。
Import an existing project
。netlify.toml
中配置。