Skip to content

Commit

Permalink
feat: keep internal provider enable (nuxt#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz authored Nov 7, 2020
1 parent 2017f75 commit 3d12703
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 47 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ node_modules
*.log
cache/
dist/
ipx
.DS_Store
coverage
sw.*
32 changes: 32 additions & 0 deletions docs/content/en/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,35 @@ export default {
}
}
```

## `ipx`

Internally nuxt image uses [ipx](https://github.com/nuxt-contrib/ipx) to modify and optimize images.

- `dir`: The root directory of the all images. By default nuxt image looks `static` dir to find original images,
- `clearCache`: The ipx has a caching stategy to clear cached images to reduce massive disk usages. You can schedule the cache cleaning job using `clearCache` option in provide options. By default this cron job is disabled.

```js{}[nuxt.config.js]
export default {
image: {
ipx: {
/**
* Public domain of your website
**/
baseURL: 'https://awesome.com/',
/**
* Internal address of your website
**/
internalBaseURL: 'http://192.168.1.100:3000/',
/**
* Input directory for images
**/
dir: '~/static',
/**
* Enable/Disabel cache cleaning cron job
**/
clearCache: false
}
}
}
```
32 changes: 2 additions & 30 deletions docs/content/en/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,8 @@ position: 5
category: Guide
---

Complete list of internal providers.

## `local`

Local provider is an integration of ipx and image module. Local provider is an specific provider that uses for development, optimizing in-project.
By default local provider looks `static` dir to find original images, You can change `dir` inside `nuxt.config`.
The local provider has a caching stategy to clear cached images to reduce massive disk usages. You can schedule the cache cleaning job using `clearCache` option in provide options. By default this cron job is disabled.

```js{}[nuxt.config.js]
export default {
image: {
providers: {
local: {
/**
* Public domain of your website
**/
baseURL: 'https://awesome.com/',
/**
* Input directory for images
**/
dir: '~/static',
/**
* Enable/Disabel cache cleaning cron job
**/
clearCache: false
}
}
}
}
```
Nuxt image have a generic way to work with external providers like Cloudinary. Here is a complete list of providers that supports out of the box.
If you looking for a specific provider outside of this list, you can [create your own provider](/custom-provider).

## `cloudinary`

Expand Down
1 change: 0 additions & 1 deletion docs/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default theme({
],
image: {
providers: {
local: {},
cloudinary: {
baseURL: 'https://res.cloudinary.com/nuxt/image/upload/'
},
Expand Down
3 changes: 1 addition & 2 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default {
'@nuxt/typescript-build'
],
image: {
defaultProvider: 'local',
presets: [
{
name: 's50',
Expand All @@ -19,7 +18,7 @@ export default {
}
],
providers: {
local: {},
ipx: false,
twicpics: {
baseURL: 'https://i5acur1u.twic.pics'
},
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import defu from 'defu'
import fs from 'fs-extra'
import upath from 'upath'
import { ModuleOptions, ProviderFactory } from 'types'
import { downloadImage, getFileExtension, hash, tryRequire } from './utils'
import { downloadImage, getFileExtension, hash, logger, tryRequire } from './utils'
import { cleanDoubleSlashes } from './runtime/utils'
export type { Provider, RuntimeProvider } from 'types'

Expand All @@ -19,13 +19,13 @@ function imageModule (moduleOptions: ModuleOptions) {
...moduleOptions
}

// Ensure local provider is set
if (!options.providers.length || options.providers.local) {
options.providers.local = prepareLocalProvider(this, options.providers.local)
if (typeof options.providers.ipx !== 'undefined') {
logger.warn("'ipx' is a reserved name for provider. Please choose another name for your provider. This provider will ignore.")
}
options.providers.ipx = prepareLocalProvider(this, options.providers.ipx || {})

if (!options.defaultProvider) {
options.defaultProvider = Object.keys(options.providers)[0]
options.defaultProvider = 'ipx'
}

interface ModuleProvider {
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion test/unit/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('Plugin', () => {
}
],
providers: {
local: {},
random: '~/providers/random',
cloudinary: {
baseURL: 'https://res.cloudinary.com/nuxt/image/upload'
Expand Down
2 changes: 1 addition & 1 deletion test/unit/providers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs-extra'
import local from '~/src/providers/local'
import local from '~/src/providers/ipx'
import cloudinary from '~/src/providers/cloudinary'
import twicpics from '~/src/providers/twicpics'
import fastly from '~/src/providers/fastly'
Expand Down
13 changes: 7 additions & 6 deletions types/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { ImagePreset } from './runtime'

export interface ModuleOptions {
defaultProvider: string;
presets: ImagePreset[],
presets: ImagePreset[];
ipx: {
baseURL: string;
dir?: string;
clearCache?: boolean | string;
}
sizes: number[],
internalUrl?: string
providers: {
local: {
dir?: string
clearCache?: boolean | string;
}
[name: string]: any
[name: string]: any;
}
intersectOptions: object;
}
Expand Down

0 comments on commit 3d12703

Please sign in to comment.