Skip to content
Permalink
Browse files

feat(option): add build option extra.minify.client[css|js]

(array of strings) = file paths: additional files to minify in dist/client that the build didn't minify (by default, the build does not minify files in libs or bower_components)
  • Loading branch information
jyounce committed Apr 29, 2016
1 parent a9f0912 commit 4124999f10085a00f62f05f8b6d81660bf49d204
@@ -192,7 +192,8 @@ package.json
# extra.copy[client|server] = (array of strings) = file paths: additional files to copy to dist/client and or dist/server that the build didn't copy
# extra.compile.client[coffee|es6|less|sass] = (array of strings) = file paths: additional files to compile to dist/client that the build didn't compile
# extra.compile.server[less|sass] = (array of strings) = file paths: additional files to compile to dist/server that the build didn't compile
# =============================================================================================================================================================================================================================
# extra.minify.client[css|js] = (array of strings) = file paths: additional files to minify in dist/client that the build didn't minify (by default, the build does not minify files in libs or bower_components)
# =====================================================================================================================================================================================================================================
```

## Build Modes
@@ -59,14 +59,18 @@ getCommonOptions = ->
less: [
'libs/bootstrap/bootstrap.less'
]
minify:
client:
css: [
'libs/bootstrap/bootstrap.css'
]

# Dev Build Options
# =================
setDevOptions = (options, build) ->
return setProdOptions options, build if build.indexOf('prod') isnt -1
logBuildMsg build, 'DEV'
options.extra.copy.client.push(
# 'bower_components/bootstrap/dist/css/bootstrap.css'
'bower_components/font-awesome/css/font-awesome.css'
)

@@ -75,7 +79,6 @@ setDevOptions = (options, build) ->
setProdOptions = (options, build) ->
logBuildMsg build, 'PROD'
options.extra.copy.client.push(
# 'bower_components/bootstrap/dist/css/bootstrap.min.css'
'bower_components/font-awesome/css/font-awesome.min.css'
)

@@ -26,6 +26,7 @@ module.exports = (rbDir, options) ->
config = require("#{config.req.config.configs}/config-extra") config
config = require("#{config.req.config.configs}/config-extra-copy") config, options
config = require("#{config.req.config.configs}/config-extra-compile") config, options
config = require("#{config.req.config.configs}/config-extra-minify") config, options
config = require("#{config.req.config.configs}/config-templates") config
config = require("#{config.req.config.configs}/config-temp") config
config = require("#{config.req.config.configs}/config-http-proxy") config, options
@@ -0,0 +1,48 @@
module.exports = (config, options) ->
path = require 'path'
log = require "#{config.req.helpers}/log"
test = require("#{config.req.helpers}/test")()

# init extra.minify
# minify additional client files [css|js]
# in dist that the build didn't minify
# =======================================
minify =
rb:
client:
css: []
js: []
app:
client:
css: options.extra.minify.client.css or []
js: options.extra.minify.client.js or []

# format minify paths
# ===================
formatMinifyPaths = (appOrRb) ->
for loc in ['client']
for lang in ['css','js']
files = minify[appOrRb][loc][lang]
continue unless files
continue unless files.length
for file, i in files
files[i] = path.join config.dist[appOrRb][loc].dir, files[i]

formatMinifyPaths 'rb'
formatMinifyPaths 'app'

# add minify to config.extra
# ==========================
config.extra.minify = minify

# logs
# ====
# log.json extra.minify, 'extra.minify ='

# tests
# =====
test.log 'true', config.extra.minify, 'add extra.minify to config'

# return
# ======
config
@@ -7,8 +7,10 @@ module.exports = (config, options) ->
extra = {} unless isType.object extra
extra.copy = {} unless isType.object extra.copy
extra.compile = {} unless isType.object extra.compile
extra.minify = {} unless isType.object extra.minify
extra.compile.client = {} unless isType.object extra.compile.client
extra.compile.server = {} unless isType.object extra.compile.server
extra.minify.client = {} unless isType.object extra.minify.client

# extra copy options
# ==================
@@ -24,6 +26,11 @@ module.exports = (config, options) ->
extra.compile.server.less = null unless isType.array extra.compile.server.less
extra.compile.server.sass = null unless isType.array extra.compile.server.sass

# extra minify options
# ====================
extra.minify.client.css = null unless isType.array extra.minify.client.css
extra.minify.client.js = null unless isType.array extra.minify.client.js

# add extra options
# =================
options.extra = extra
@@ -19,6 +19,19 @@ module.exports = (config, gulp) ->
defer.resolve()
defer.promise

runExtraTask = (appOrRb) ->
defer = q.defer()
src = config.extra.minify[appOrRb].client.css
return promiseHelp.get() unless src.length
dest = config.dist[appOrRb].client.dir
gulp.src src, base: dest
.pipe minifyCss minOpts
.pipe gulp.dest dest
.on 'end', ->
console.log "minified extra #{appOrRb} dist styles".yellow
defer.resolve()
defer.promise

# API
# ===
api =
@@ -28,6 +41,7 @@ module.exports = (config, gulp) ->
q.all([
runTask 'rb'
runTask 'app'
runExtraTask 'app'
]).done -> defer.resolve()
defer.promise

@@ -1,31 +1,46 @@
module.exports = (config, gulp) ->
q = require 'q'
gulpif = require 'gulp-if'
minifyJs = require 'gulp-uglify'
q = require 'q'
gulpif = require 'gulp-if'
minifyJs = require 'gulp-uglify'
promiseHelp = require "#{config.req.helpers}/promise"

runTask = (appOrRb) ->
defer = q.defer()
minify = config.minify.js.scripts
minOpts = mangle: config.minify.js.mangle
src = config.glob.dist[appOrRb].client.scripts.all
dest = config.dist[appOrRb].client.scripts.dir
runTask = (appOrRb, minify, opts) ->
defer = q.defer()
src = config.glob.dist[appOrRb].client.scripts.all
dest = config.dist[appOrRb].client.scripts.dir
src.push '!**/*.json' # do not minify json files, uglify has issues with quoted keys
gulp.src src
.pipe gulpif minify, minifyJs minOpts
.pipe gulpif minify, minifyJs opts
.pipe gulp.dest dest
.on 'end', ->
console.log "minified #{appOrRb} dist scripts".yellow
defer.resolve()
defer.promise

runExtraTask = (appOrRb, minify, opts) ->
defer = q.defer()
src = config.extra.minify[appOrRb].client.js
return promiseHelp.get() unless src.length
dest = config.dist[appOrRb].client.dir
gulp.src src, base: dest
.pipe gulpif minify, minifyJs opts
.pipe gulp.dest dest
.on 'end', ->
console.log "minified extra #{appOrRb} dist scripts".yellow
defer.resolve()
defer.promise

# API
# ===
api =
runTask: ->
defer = q.defer()
defer = q.defer()
minify = config.minify.js.scripts
opts = mangle: config.minify.js.mangle
q.all([
runTask 'rb'
runTask 'app'
runTask 'rb', minify, opts
runTask 'app', minify, opts
runExtraTask 'app', minify, opts
]).done -> defer.resolve()
defer.promise

0 comments on commit 4124999

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