Skip to content
Permalink
Browse files

feat(minify): add task css-file-split for lte ie9, split styles.min.c…

…ss into multiple files if selector count > 4,095
  • Loading branch information
jyounce committed Jun 30, 2015
1 parent 346ff1d commit 9a40c94fcd5d94c649e2125333a4a40cb26c24a1
Showing with 47 additions and 0 deletions.
  1. +1 −0 init/tasks.coffee
  2. +1 −0 package.json
  3. +44 −0 tasks/minify/css-file-split.coffee
  4. +1 −0 tasks/minify/minify-client.coffee
@@ -57,6 +57,7 @@ module.exports = (gulp, config) ->
# minify
# ======
require("#{config.req.tasks}/minify/concat-scripts-and-styles") gulp, config # concat-scripts-and-styles
require("#{config.req.tasks}/minify/css-file-split") gulp, config # css-file-split
require("#{config.req.tasks}/minify/minify-client") gulp, config # minify-client
require("#{config.req.tasks}/minify/minify-css") gulp, config # minify-css
require("#{config.req.tasks}/minify/minify-html") gulp, config # minify-html
@@ -35,6 +35,7 @@
"gulp": "~3.9.0",
"gulp-angular-templatecache": "~1.7.0",
"gulp-babel": "~5.1.0",
"gulp-bless": "~3.0.1",
"gulp-coffee": "~2.3.1",
"gulp-concat": "~2.6.0",
"gulp-if": "~1.2.5",
@@ -0,0 +1,44 @@
# FOR IE 9 AND BELOW - (for prod build, run against styles.min.css)
# Selector limit per stylesheet: 4,095
# Fortunately IE 10 ups the limit to: 65,534
# If you don't care about those piece of shit browsers, then disable this option.
# ===============================================================================
module.exports = (gulp, config) ->
q = require 'q'
fs = require 'fs'
path = require 'path'
bless = require 'gulp-bless'

# tasks
# =====
runTask = (src, dest, file, basename, ext) ->
defer = q.defer()
opts = imports:false, force:true
cnt = 1
didSplit = false
gulp.src src
.pipe bless opts
.on 'data', (_file) -> # change the name so the glob order will be correct
isBlessedFile = _file.basename.indexOf('blessed') isnt -1
didSplit = isBlessedFile or cnt > 1
return unless didSplit
fs.unlinkSync _file.path unless isBlessedFile # remove styles.min.css
_file.basename = "#{basename}.#{cnt}.#{ext}"
cnt++ if isBlessedFile
.pipe gulp.dest dest
.on 'end', ->
console.log "#{file} split into #{cnt} files".yellow if didSplit
defer.resolve()
defer.promise

# register task
# =============
gulp.task "#{config.rb.prefix.task}css-file-split", ->
stylesDir = config.dist.app.client.styles.dir
minFile = config.fileName.styles.min
minPath = path.join stylesDir, minFile
ext = 'css'
basename = path.basename minFile, ".#{ext}"
runTask minPath, stylesDir, minFile, basename, ext


@@ -13,6 +13,7 @@ module.exports = (gulp, config) ->
]
"#{config.rb.prefix.task}concat-scripts-and-styles"
"#{config.rb.prefix.task}cleanup-client"
"#{config.rb.prefix.task}css-file-split"
"#{config.rb.prefix.task}build-files-prod"
"#{config.rb.prefix.task}build-spa"
"#{config.rb.prefix.task}minify-spa"

0 comments on commit 9a40c94

Please sign in to comment.
You can’t perform that action at this time.