Skip to content

Commit

Permalink
feat(icon): add combined option sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Pennec authored and pi0 committed Mar 3, 2018
1 parent afebd96 commit 539430f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 8 additions & 0 deletions docs/modules/icon.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

This module automatically generates app icons and favicon with different sizes using [jimp](https://github.com/oliver-moran/jimp) and fills `manifest.icons[]` with proper paths to generated assets that is used by manifest module. Source icon is being resized using *cover* method.


You can pass options to `icon` section in `nuxt.config.js` to override defaults.

```js
icon: {
// Icon options
}
```
### options

**iconSrc**
Expand Down
13 changes: 8 additions & 5 deletions packages/icon/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs-extra')
const { existsSync } = require('fs-extra')
const path = require('path')
const Jimp = require('jimp')
const debug = require('debug')('nuxt:pwa')
Expand All @@ -19,7 +19,10 @@ module.exports = function nuxtIcon (options) {
this.nuxt.hook ? this.nuxt.hook('build:before', hook) : this.nuxt.plugin('build', hook)
}

function generateIcons (options) {
function generateIcons (moduleOptions) {
// Combine sources
const options = Object.assign({}, this.options.icon, moduleOptions)

const iconSrc = options.iconSrc || path.resolve(this.options.srcDir, 'static', 'icon.png')
const sizes = options.sizes || [64, 120, 144, 152, 192, 384, 512]

Expand All @@ -29,12 +32,12 @@ function generateIcons (options) {
if (isUrl(this.options.build.publicPath)) { // CDN
publicPath = this.options.build.publicPath
if (publicPath.indexOf('//') === 0) {
publicPath = '/' + publicPath // escape fixUrl
publicPath = `/${publicPath}` // escape fixUrl
}
}

// Ensure icon file exists
if (!fs.existsSync(iconSrc)) {
if (!existsSync(iconSrc)) {
/* eslint-disable no-console */
debug(path.relative(this.options.srcDir, iconSrc), 'not found! Please create one or disable icon module.')
return
Expand All @@ -48,7 +51,7 @@ function generateIcons (options) {
if (err) {
return reject(err)
}
let fileName = `icons/icon_${size}.${hash}.png`
const fileName = `icons/icon_${size}.${hash}.png`
resolve({ size, buff, fileName })
})
}))).then(icons => {
Expand Down

0 comments on commit 539430f

Please sign in to comment.