Skip to content

Commit b2d8f89

Browse files
committed
feat: add CDN support in static export
1 parent 5a465ea commit b2d8f89

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ In a few scenarios, you may want to deploy your blog on a CDN or other static se
123123
npm run export
124124
```
125125

126-
After running the command, the generated static file will be in the `/out` directory.
126+
After running the command, the generated static file will be in the `/out` directory. If you want to set the prefix of the CDN,
127+
please set the environment variable:
128+
129+
```bash
130+
# set CDN prefix
131+
export CDN_PREFIX=https://unix.bio
132+
npm run export
133+
```
127134

128135
<br />
129136

README_CN.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ npx unix-bio migrate
122122
npm run export
123123
```
124124

125-
在运行命令后,静态文件会生成在 `/out` 文件夹。
125+
在运行导出命令后,静态文件会生成在 `/out` 文件夹。如果您想要自定义 CDN 的域名前缀,可以声明环境变量后再运行导出命令:
126+
127+
```bash
128+
# cdn prefix
129+
export CDN_PREFIX=https://unix.bio
130+
npm run export
131+
```
126132

127133
如果你使用自定义的静态部署,将无法获得最好的性能,同时未来所有与服务端渲染、混合渲染相关的功能也不受支持。
128134
此外,静态部署需要您自行解决各类路径与缓存问题。(请不要在 `issues` 中提此类问题)

next.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
const isProd = process.env.NODE_ENV === 'production'
2+
const cdnPrefix = process.env.CDN_PREFIX || ''
3+
4+
if (isProd && cdnPrefix) {
5+
console.log(`> [unix.bio] You have customized the CDN prefix: ${cdnPrefix}.\n`)
6+
}
7+
18
const withMDX = require('@next/mdx')({
29
extension: /\.(md|mdx)?$/,
310
options: {
@@ -12,6 +19,12 @@ const nextConfig = {
1219

1320
cssModules: true,
1421

22+
generateEtags: false,
23+
24+
poweredByHeader: false,
25+
26+
assetPrefix: isProd ? cdnPrefix : '',
27+
1528
cssLoaderOptions: {
1629
importLoaders: 1,
1730
localIdentName: '[local]___[hash:base64:5]',

0 commit comments

Comments
 (0)