-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: lazy import preload, then update include.type to include.as
- Loading branch information
1 parent
7d70738
commit 6bb0e46
Showing
9 changed files
with
63 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@modern-js/prod-server': patch | ||
'@modern-js/server-core': patch | ||
--- | ||
|
||
fix: lazy import preload, then update include.type to include.as | ||
fix: 动态加载 preload 功能, 对齐规范将 include.type 属性更新为 include.as |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/server/prod-server/src/libs/preload/shouldFlushServerHeader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { ServerOptions } from '@modern-js/server-core'; | ||
|
||
export function transformToRegExp(input: string | RegExp): RegExp { | ||
if (typeof input === 'string') { | ||
return new RegExp(input); | ||
} | ||
return input; | ||
} | ||
|
||
export function shouldFlushServerHeader( | ||
serverConf: ServerOptions['server'], | ||
userAgent?: string, | ||
disablePreload?: boolean, | ||
) { | ||
const { ssr: ssrConf } = serverConf || {}; | ||
|
||
if (disablePreload) { | ||
return false; | ||
} | ||
|
||
if (typeof ssrConf === 'object' && ssrConf.preload) { | ||
// ssr.preload: 'object' | ||
if (typeof ssrConf.preload === 'object') { | ||
const { userAgentFilter } = ssrConf.preload; | ||
if (userAgentFilter && userAgent) { | ||
return !transformToRegExp(userAgentFilter).test(userAgent); | ||
} | ||
return true; | ||
} | ||
// ssr.preload: true; | ||
return true; | ||
} | ||
|
||
// ssr: false or ssr: true | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters