Last active
January 11, 2019 15:35
-
-
Save silvandiepen/3335d6356127425006d5f945cb3dd54b to your computer and use it in GitHub Desktop.
Create Vue Svg Icon files
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
const fs = require('fs'); | |
const nuxtConfig = 'nuxt.config.js'; | |
String.prototype.splice = function(idx, rem, str) { | |
return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem)); | |
}; | |
fs.readFile(nuxtConfig, 'utf8', function(err, data) { | |
if (err) { | |
return console.log(err); | |
} | |
console.log(data) | |
if(data.indexOf('~plugins/vue-svgicon') > -1){ | |
console.log('svgicon is already installed in your nuxt config'); | |
} else { | |
let insertAt = data.indexOf('plugins: [') + 11; | |
data = data.splice(insertAt, 0, "{ src: '~plugins/vue-svgicon' },") | |
} | |
fs.writeFile(nuxtConfig, data, 'utf8', function(err) { | |
if (err) return console.log(err); | |
}); | |
}); |
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
#!/usr/bin/env bash | |
# Install JSON to run this script | |
npm i -g json | |
# Install the vue-svgicon package to your project | |
npm i vue-svgicon --save | |
# Create a folder for the icons | |
mkdir -p assets/icons | |
# Add the generate to your package.json | |
json -I -f package.json -e 'this.scripts.svg="vsvg -s assets/icons -t components/icons --es6"' | |
# Add the package to your plugins | |
curl -o plugins/vue-svgicon.js -l https://gist.githubusercontent.com/silvandiepen/3335d6356127425006d5f945cb3dd54b/raw/vue-svgicon.js | |
node <(curl -s https://gist.githubusercontent.com/silvandiepen/3335d6356127425006d5f945cb3dd54b/raw/add-vue-svg-icon.js) | |
# { src: '~plugins/vue-svgicon' }, -- Need to be added to nuxt.config.js | |
printf 'You\'ve added the folders necessary for Vue-Svgicon' | |
printf 'Place your SVG files in assets/icons' | |
printf 'Run `npm run svg` to extract your icons' |
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
import Vue from 'vue'; | |
import SvgIcon from 'vue-svgicon'; | |
// Default tag name is 'svgicon' | |
Vue.use(SvgIcon, { | |
tagName: 'svgicon' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment