Skip to content
Permalink
Browse files

feat(options): add minification options via the minify object

  • Loading branch information
jyounce committed Jun 24, 2015
1 parent c53d1eb commit bc288dc603a4e9d49b9dc0ee4410e4087d06c9e6
@@ -88,6 +88,11 @@ gulp rapid-build:prod
# spa.src.dir = (string) defaults to null = set if you are using your own spa file and that file is located in a directory in your client src directory
# spa.dist.file = (string) defaults to spa.src.file or 'spa.html' = provide if you want the dist spa file to be named differently, example: 'index.html'
# spa.exclude = (array of strings) = set to retain spa file placeholders, optional values are: ['scripts', 'styles', 'description', 'moduleName', 'title'] or ['all']
# minify.css.styles = (boolean) defaults to true = for prod build, minify the css
# minify.html.views = (boolean) defaults to true = for prod build, minify the html
# minify.html.templateCache = (boolean) defaults to true = for prod build, use the template cache
# minify.js.scripts = (boolean) defaults to true = for prod build, minify the js
# minify.js.mangle = (boolean) defaults to true = for prod build, mangle the names in the js
# ==========================================================================================================================================================================================================
```

@@ -123,6 +128,7 @@ gulp rapid-build:prod
1. run common tasks (see above)
2. minify the application files
* css
* html
* js
3. concatenate files
* css (styles.min.css created)
@@ -15,6 +15,7 @@ module.exports = (rbDir, options) ->
config = require("#{config.req.config}/config-app") config, options
config = require("#{config.req.config}/config-file-names") config
config = require("#{config.req.config}/config-angular") config, options
config = require("#{config.req.config}/config-minify") config, options
config = require("#{config.req.config}/config-dist-and-src") config, options
config = require("#{config.req.config}/config-spa") config, options
config = require("#{config.req.config}/config-templates") config
@@ -5,17 +5,24 @@ module.exports = (config, options) ->

# helpers
# =======
getOption = (opt) ->
opt = options.minify[opt]
getOption = (type, opt) ->
opt = options.minify[type][opt]
return true if isType.null opt
opt

# init minify
# ===========
minify =
css: getOption 'css'
html: getOption 'html'
js: getOption 'js'
css:
styles: getOption 'css', 'styles'
js:
scripts: getOption 'js', 'scripts'
mangle: getOption 'js', 'mangle'
html:
views: getOption 'html', 'views'
templateCache: getOption 'html', 'templateCache'
options: # not configurable
conditionals:true, empty:true, ssi:true

# add minify to config
# ====================
@@ -27,13 +27,18 @@
# spa.src.dir = (string) defaults to null
# spa.dist.file = (string) defaults to spa.src.file or 'spa.html'
# spa.exclude = (array of strings) = optionals: ['scripts', 'styles', 'description', 'moduleName', 'title'] or ['all']
# minify.css.styles = (boolean) defaults to true
# minify.html.views = (boolean) defaults to true
# minify.html.templateCache = (boolean) defaults to true
# minify.js.scripts = (boolean) defaults to true
# minify.js.mangle = (boolean) defaults to true
# =====================================================================================================================================================
module.exports = (config, options) ->
log = require "#{config.req.helpers}/log"
isType = require "#{config.req.helpers}/isType"

# format options
# ==============
# format options helpers
# ======================
distAndSrcOptions = ->
['dist', 'src'].forEach (v1) ->
options[v1] = {} if not isType.object options[v1]
@@ -88,12 +93,26 @@ module.exports = (config, options) ->
options.spa.src.file = null if not isType.string options.spa.src.file
options.spa.dist.file = null if not isType.string options.spa.dist.file

distAndSrcOptions()
minifyOptions = ->
options.minify = {} if not isType.object options.minify
options.minify.css = {} if not isType.object options.minify.css
options.minify.html = {} if not isType.object options.minify.html
options.minify.js = {} if not isType.object options.minify.js
options.minify.css.styles = null if not isType.boolean options.minify.css.styles
options.minify.html.views = null if not isType.boolean options.minify.html.views
options.minify.html.templateCache = null if not isType.boolean options.minify.html.templateCache
options.minify.js.scripts = null if not isType.boolean options.minify.js.scripts
options.minify.js.mangle = null if not isType.boolean options.minify.js.mangle

# init
# ====
distAndSrcOptions() # must be first
serverOptions()
portOptions()
orderOptions()
angularOptions()
spaOptions()
minifyOptions()

# logs
# ====
@@ -55,6 +55,7 @@ module.exports = (gulp, config) ->
require("#{config.req.tasks}/minify/concat-scripts-and-styles") gulp, config # concat-scripts-and-styles
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
require("#{config.req.tasks}/minify/minify-images") gulp, config # minify-images
require("#{config.req.tasks}/minify/minify-js") gulp, config # minify-js
require("#{config.req.tasks}/minify/minify-server") gulp, config # minify-server
@@ -5,7 +5,10 @@ module.exports = (gulp, config) ->
# =============
gulp.task "#{config.rb.prefix.task}copy-views", (cb) ->
if config.env.name is 'prod'
task = 'template-cache'
if config.minify.html.templateCache
task = 'template-cache'
else
task = 'copy-html'
else if config.angular.templateCache.dev.enable
task = 'template-cache'
else
@@ -7,6 +7,7 @@ module.exports = (gulp, config) ->
gulpSequence(
[
"#{config.rb.prefix.task}minify-css"
"#{config.rb.prefix.task}minify-html"
"#{config.rb.prefix.task}minify-images"
"#{config.rb.prefix.task}minify-js"
]
@@ -1,11 +1,13 @@
module.exports = (gulp, config) ->
q = require 'q'
gulpif = require 'gulp-if'
minifyCss = require 'gulp-minify-css'

runTask = (appOrRb) ->
defer = q.defer()
defer = q.defer()
minify = config.minify.css.styles
gulp.src config.glob.dist[appOrRb].client.styles.all
.pipe minifyCss()
.pipe gulpif minify, minifyCss()
.pipe gulp.dest config.dist[appOrRb].client.styles.dir
.on 'end', ->
console.log "minified #{appOrRb} dist styles".yellow
@@ -0,0 +1,58 @@
module.exports = (gulp, config) ->
q = require 'q'
path = require 'path'
minifyHtml = require 'gulp-minify-html'

minifyTask = (appOrRb) ->
defer = q.defer()
return if not config.minify.html.views
defer.resolve()
defer.promise
minOpts = config.minify.html.options
gulp.src config.glob.dist[appOrRb].client.views.all
.pipe minifyHtml minOpts
.pipe gulp.dest config.dist[appOrRb].client.views.dir
.on 'end', ->
console.log "minified #{appOrRb} dist views".yellow
defer.resolve()
defer.promise

minifyTasks = ->
defer = q.defer()
q.all([
minifyTask 'rb'
minifyTask 'app'
]).done -> defer.resolve()
defer.promise

moveTask = -> # move to rb .temp folder
defer = q.defer()
src = "#{config.glob.dist.rb.client.views.all}/*"
dest = path.join(
config.temp.client.dir
config.rb.prefix.distDir
config.dist.rb.client.views.dirName
)
gulp.src src
.pipe gulp.dest dest
.on 'end', ->
console.log "copied rb views".yellow
defer.resolve()
defer.promise

runTasks = ->
defer = q.defer()
minifyTasks().done ->
moveTask().done ->
defer.resolve()
defer.promise

# register task
# =============
gulp.task "#{config.rb.prefix.task}minify-html", ->
return runTasks() if not config.minify.html.templateCache
defer = q.defer()
defer.resolve()
defer.promise


@@ -2,7 +2,7 @@ module.exports = (gulp, config) ->
q = require 'q'
path = require 'path'

moveTask = (src, dest) ->
moveTask = (src, dest) -> # move to rb .temp folder
defer = q.defer()
gulp.src src
.pipe gulp.dest dest
@@ -1,12 +1,14 @@
module.exports = (gulp, config) ->
q = require 'q'
gulpif = require 'gulp-if'
minifyJs = require 'gulp-uglify'

runTask = (appOrRb) ->
defer = q.defer()
defer = q.defer()
minify = config.minify.js.scripts
minOpts = mangle: config.minify.js.mangle
gulp.src config.glob.dist[appOrRb].client.scripts.all
# .pipe minifyJs mangle:false
.pipe minifyJs()
.pipe gulpif minify, minifyJs minOpts
.pipe gulp.dest config.dist[appOrRb].client.scripts.dir
.on 'end', ->
console.log "minified #{appOrRb} dist scripts".yellow
@@ -5,9 +5,10 @@ module.exports = (gulp, config) ->
# tasks
# =====
runTask = (src, dest, file) ->
defer = q.defer()
defer = q.defer()
minOpts = config.minify.html.options
gulp.src src
.pipe minifyHtml empty:true, conditionals:true, ssi:true
.pipe minifyHtml minOpts
.pipe gulp.dest dest
.on 'end', ->
console.log "minified #{file}".yellow
@@ -39,13 +39,15 @@ module.exports = (gulp, config, watchFile={}) ->
# tasks
# =====
runTask = (src, dest, file, isProd) ->
defer = q.defer()
opts = {}
defer = q.defer()
minify = isProd and config.minify.html.views
minOpts = config.minify.html.options
opts = {}
opts.root = '/' if config.angular.templateCache.useAbsolutePaths
opts.module = config.angular.moduleName
gulp.src src
.pipe addToDistPath()
.pipe gulpif isProd, minifyHtml empty:true, conditionals:true, ssi:true
.pipe gulpif minify, minifyHtml minOpts
.pipe templateCache file, opts
.pipe gulp.dest dest
.on 'end', ->

0 comments on commit bc288dc

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