Skip to content

Commit

Permalink
feat: 🚀 Introduced new 'externalOutputDir' config flag
Browse files Browse the repository at this point in the history
Introduced this flag to allow users to define their own external images
download directory.
  • Loading branch information
itsmejoeeey committed Aug 25, 2022
1 parent e439bc1 commit e585af9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/docs/04-Configurations/01-basic-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ e.g. If `'_optimized'` is set.
+ out/_optimized/filename.png
```

### `externalImageDir`

- Type: string
- Default: '\_next/static/media'

You can customize the directory to output downloaded external images.
The default is `'_next/static/media'`.


### `basePath`

- Type: string
Expand Down
5 changes: 4 additions & 1 deletion src/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const exportableLoader: ImageLoader = ({ src: _src, width, quality }) => {
const outputDir = `/${
config.imageDir ? config.imageDir.replace(/^\//, '').replace(/\/$/, '') : '_next/static/chunks/images'
}`
const externalOutputDir = `/${
config.externalImageDir ? config.externalImageDir.replace(/^\//, '').replace(/\/$/, '') : '_next/static/media'
}`
const filename =
config.filenameGenerator !== undefined
? config.filenameGenerator({ path: pathWithoutName, name, width, quality: quality || 75, extension })
Expand All @@ -65,7 +68,7 @@ const exportableLoader: ImageLoader = ({ src: _src, width, quality }) => {
const path = require('path') as typeof import('path')

if (src.startsWith('http')) {
json.src = `/_next/static/media/${src
json.src = `/${externalOutputDir}/${src
.replace(/^https?:\/\//, '')
.split('/')
.slice(1)
Expand Down
7 changes: 7 additions & 0 deletions src/utils/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export type Config = {
*
* @type {string}
*/
externalImageDir?: string
/**
* You can customize the directory to output downloaded external images.
* The default is '_next/static/media'
*
* @type {string}
*/
basePath?: string
/**
* You can customize the generation of file names.
Expand Down

0 comments on commit e585af9

Please sign in to comment.