-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add multiple cdn * add multiple cdn test * assetsPrefix not empty string * add changeset * simplify code * change docs * replace getFileExtension with node path.extname * Adapt node extname * multiple image test * wip space * update docs * update docs, assetsPrefix type * update docs * update docs * chore: update types and rename to `fallback` * enhance changelog * change docs * update change defaultAeestsPrefix to fallback key test * move utility to a new to avoid importing `node:path` inside vite plugins * Update packages/astro/src/@types/astro.ts Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * chore: address Bjorn's comments * kill the variable * kill the variable /2 * Fix CI fail * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * uniform code sample * add `.` string for fit getAssetsPrefix * Fix extension function --------- Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: bluwy <bjornlu.dev@gmail.com> Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
- Loading branch information
1 parent
d933666
commit 1ea0a25
Showing
13 changed files
with
289 additions
and
37 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,26 @@ | ||
--- | ||
"@astrojs/internal-helpers": minor | ||
"astro": minor | ||
--- | ||
|
||
Adds the option to pass an object to `build.assetsPrefix`. This allows for the use of multiple CDN prefixes based on the target file type. | ||
|
||
When passing an object to `build.assetsPrefix`, you must also specify a `fallback` domain to be used for all other file types not specified. | ||
|
||
Specify a file extension as the key (e.g. 'js', 'png') and the URL serving your assets of that file type as the value: | ||
|
||
```js | ||
// astro.config.mjs | ||
import { defineConfig } from "astro/config" | ||
|
||
export default defineConfig({ | ||
build: { | ||
assetsPrefix: { | ||
'js': "https://js.cdn.example.com", | ||
'mjs': "https://js.cdn.example.com", // if you have .mjs files, you must add a new entry like this | ||
'png': "https://images.cdn.example.com", | ||
'fallback': "https://generic.cdn.example.com" | ||
} | ||
} | ||
}) | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { AssetsPrefix } from '../../core/app/types.js'; | ||
|
||
export function getAssetsPrefix(fileExtension: string, assetsPrefix?: AssetsPrefix): string { | ||
if (!assetsPrefix) return ''; | ||
if (typeof assetsPrefix === 'string') return assetsPrefix; | ||
// we assume the file extension has a leading '.' and we remove it | ||
const dotLessFileExtension = fileExtension.slice(1); | ||
if (assetsPrefix[dotLessFileExtension]) { | ||
return assetsPrefix[dotLessFileExtension]; | ||
} | ||
return assetsPrefix.fallback; | ||
} |
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
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
Oops, something went wrong.