Skip to content

Commit 12e6576

Browse files
ricardogobbosouzapi0
authored andcommitted
feat(icon): new options (#126)
1 parent 17e4e0f commit 12e6576

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

docs/modules/icon.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ icon: {
1616
### options
1717

1818
**iconSrc**
19-
- Default: `[srcDir]/static/icon.png`
19+
- Default: `[srcDir]/[staticDir]/icon.png`
20+
21+
**iconFileName**
22+
- Default: `icon.png`
2023

2124
**sizes**
2225
- Default: `[16, 120, 144, 152, 192, 384, 512]`
2326

27+
**targetDir**
28+
- Default: `icons`
29+
2430
Array of sizes to be generated (Square).
2531

2632
**accessibleIcons**

packages/icon/index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ module.exports = function nuxtIcon (options) {
2121

2222
function generateIcons (moduleOptions) {
2323
// Combine sources
24-
const options = Object.assign({}, this.options.icon, moduleOptions)
25-
26-
const iconSrc = options.iconSrc || path.resolve(this.options.srcDir, 'static', 'icon.png')
27-
const sizes = options.sizes || [64, 120, 144, 152, 192, 384, 512]
24+
const defaults = {
25+
iconSrc: null,
26+
iconFileName: 'icon.png',
27+
sizes: [64, 120, 144, 152, 192, 384, 512],
28+
targetDir: 'icons'
29+
}
30+
const options = Object.assign({}, defaults, this.options.icon, moduleOptions)
31+
const iconSrc = options.iconSrc || path.resolve(this.options.srcDir, this.options.dir.static, options.iconFileName)
2832

2933
// routerBase and publicPath
3034
const routerBase = this.options.router.base
@@ -46,12 +50,12 @@ function generateIcons (moduleOptions) {
4650
return Jimp.read(iconSrc).then(srcIcon => {
4751
// get base64 phash of source image
4852
const hash = srcIcon.hash()
49-
return Promise.all(sizes.map(size => new Promise((resolve, reject) => {
53+
return Promise.all(options.sizes.map(size => new Promise((resolve, reject) => {
5054
srcIcon.clone().contain(size, size).getBuffer(Jimp.MIME_PNG, (err, buff) => {
5155
if (err) {
5256
return reject(err)
5357
}
54-
const fileName = `icons/icon_${size}.${hash}.png`
58+
const fileName = `${options.targetDir}/icon_${size}.${hash}.png`
5559
resolve({ size, buff, fileName })
5660
})
5761
}))).then(icons => {

test/__snapshots__/pwa.test.js.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Array [
88
"fixture/.nuxt/components/no-ssr.js",
99
"fixture/.nuxt/components/nuxt-child.js",
1010
"fixture/.nuxt/components/nuxt-error.vue",
11-
"fixture/.nuxt/components/nuxt-link.js",
11+
"fixture/.nuxt/components/nuxt-link.client.js",
12+
"fixture/.nuxt/components/nuxt-link.server.js",
1213
"fixture/.nuxt/components/nuxt-loading.vue",
1314
"fixture/.nuxt/components/nuxt.js",
1415
"fixture/.nuxt/dist",

0 commit comments

Comments
 (0)