You are supposed to have this project layout:
node_modules/
bower_components/
coffee/
jade/
scss/
svg/
2png/
icons/
www/
bower.json
package.json
gulpfile.js
-
gulp build
- convert
coffee/*.coffee
towww/*.js
- convert
jade/*.jade
towww/*.html
- convert
scss/*.scss
towww/*.css
- convert
svg/2png/*.svg
towww/*.png
see bellow - merge
svg/icons/*.svg
into a singlewww/mdicons.svg
see bellow
- convert
-
gulp dist
the samebuild
does, but- html is not pretty
- JS is minified
- JS has no Maps
-
gulp
will build and then watch for changes (except for PNG files)
I like to draw a lot of glyphs in a single SVG file. So I have groups of images per SVG file.
This gulpfile will parse all SVG inside the svg/2png
folder, and export to www/*.png
all objects that match a regex.
In this case the object name need to start with xx
, so, if inside the SVG file you have an object named xxbtn_add
it will be extracted as www/btn_add.png
.
Also all color #f2f2f2
are going to be converted to none
(transparent). So is easy to define a gray rectangle with desired size, put some vectors inside and at the end you will have a transparent PNG image with the correct size and vectors well positioned.
You must have Inkscape in your path.
Supposing you are using Angular Material.
You can download SVG icons from Material Icons and copy them inside svg/icons/
.
This gulpfile will merge them into a single SVG file named www/mdicons.svg
.
You need to load this file:
app.config ($mdIconProvider) ->
$mdIconProvider.defaultIconSet 'mdicons.svg'
And them use it:
//- jade
md-icon(md-svg-icon="search_white")
<!-- html -->
<md-icon md-svg-icon="search_white"></md-icon>
The name search_white
came from the original file name i.e. svg/icons/search_white.svg
.
Here is a piece of my package.json with all dependencies:
"dependencies": {
"gulp": "^3.9.1",
"gulp-coffee": "^2.3.1",
"gulp-jade": "^1.1.0",
"gulp-ng-annotate": "^2.0.0",
"gulp-sass": "^2.2.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-svg-ngmaterial": "^2.0.2",
"gulp-svgmin": "^1.2.2",
"gulp-uglify": "^1.5.3",
"gulp-util": "^3.0.7",
"shelljs": "^0.6.0"
}
There is no structure inside www/
? You have JS, CSS, HTML, SVG all together?
Yes, I don't care!
My code is organized outside of www/
. There is no code to be tweaked inside it. Actually they should be concatenated into a single file (per type), for distribution, so why should I care?