Skip to content
Permalink
Browse files

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

  • Loading branch information
jyounce committed Sep 25, 2015
1 parent dfc52f3 commit d020567e5e8f06ae4f3f12070e51841f9359757e
@@ -134,10 +134,12 @@ gulp rapid-build:test:prod
# spa.dist.fileName = (string) defaults to file name of spa.src.filePath or 'spa.html' = provide if you want the dist spa file to be named differently, example: 'index.html'
# spa.placeholders = (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.css.fileName = (string) defaults to 'styles.min.css'
# minify.css.splitMinFile = (boolean) defaults to true = for prod build, task for ie9 and below, split styles.min.css into multiple files if selector count > 4,095
# 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.fileName = (string) defaults to 'scripts.min.js'
# minify.js.mangle = (boolean) defaults to true = for prod build, mangle the names in the js
# minify.spa.file = (boolean) defaults to true = for prod build, minify the spa.html file
# minify.cacheBust = (boolean) defaults to true = for prod build, ensures the user always receives the latest files, adds an md5 checksum to the client files before their extension
@@ -17,8 +17,8 @@ module.exports = (rbDir, options) ->
config = require("#{config.req.config}/config-ports") config, options
config = require("#{config.req.config}/config-server") config
config = require("#{config.req.config}/config-browser") config, options
config = require("#{config.req.config}/config-file-names") config
config = require("#{config.req.config}/config-minify") config, options
config = require("#{config.req.config}/config-file-names") config
config = require("#{config.req.config}/config-dist-and-src") config, options
config = require("#{config.req.config}/config-angular") config, options
config = require("#{config.req.config}/config-spa") config, options
@@ -21,10 +21,10 @@ module.exports = (config) ->
fileName =
scripts:
load: loadScriptFiles
min: 'scripts.min.js'
min: config.minify.js.fileName
styles:
load: loadStylesFiles
min: 'styles.min.css'
min: config.minify.css.fileName
views:
main: 'views.js'
min: 'views.min.js'
@@ -10,15 +10,25 @@ module.exports = (config, options) ->
return true if isType.null opt
opt

getFileName = (type, lang) ->
ext = ".#{lang}"
fName = options.minify[lang].fileName
return "#{type}.min#{ext}" unless fName # default ex: scripts.min.js
hasExt = fName.indexOf(ext) isnt -1
fName += ext unless hasExt
fName

# init minify
# ===========
minify =
css:
styles: getOption 'css', 'styles'
splitMinFile: getOption 'css', 'splitMinFile'
fileName: getFileName 'styles', 'css'
js:
scripts: getOption 'js', 'scripts'
mangle: getOption 'js', 'mangle'
fileName: getFileName 'scripts', 'js'
html:
views: getOption 'html', 'views'
templateCache: getOption 'html', 'templateCache'
@@ -74,10 +74,12 @@ module.exports = (config, options) ->
options.minify.spa = {} unless isType.object options.minify.spa
options.minify.cacheBust = null unless isType.boolean options.minify.cacheBust
options.minify.css.styles = null unless isType.boolean options.minify.css.styles
options.minify.css.fileName = null unless isType.string options.minify.css.fileName
options.minify.css.splitMinFile = null unless isType.boolean options.minify.css.splitMinFile
options.minify.html.views = null unless isType.boolean options.minify.html.views
options.minify.html.templateCache = null unless isType.boolean options.minify.html.templateCache
options.minify.js.scripts = null unless isType.boolean options.minify.js.scripts
options.minify.js.fileName = null unless isType.string options.minify.js.fileName
options.minify.js.mangle = null unless isType.boolean options.minify.js.mangle
options.minify.spa.file = null unless isType.boolean options.minify.spa.file

@@ -45,6 +45,7 @@ pathHelp =

getRelative: (paths) ->
_path = path.resolve paths.abs, paths.url
pathHelp.format _path

getAbsolute: (paths, opts) ->
prependPath = opts.prependPath isnt false
@@ -68,10 +68,11 @@ module.exports = (gulp, config) ->
cnt++
minCnt++
exclude = false
fileName = path.basename config.fileName[type].min, ".#{ext}"
MinFiles[type].push(
cnt: cnt
type: 'include'
name: "#{type}.min.#{minCnt}.#{ext}"
name: "#{fileName}.#{minCnt}.#{ext}"
files: []
)
MinFiles[type][cnt-1].files.push file
@@ -87,7 +88,7 @@ module.exports = (gulp, config) ->
includes.index = i
# console.log file.type
return promiseHelp.get() unless includes.total is 1
MinFiles[type][includes.index].name = "#{type}.min.#{ext}"
MinFiles[type][includes.index].name = config.fileName[type].min
promiseHelp.get()

# Multi Tasks
@@ -119,9 +119,10 @@ module.exports = (gulp, config) ->
# =============
gulp.task "#{config.rb.prefix.task}css-file-split", ->
return promiseHelp.get() if not config.minify.css.splitMinFile
ext = '.css'
dest = config.dist.app.client.styles.dir
src = path.join dest, "{styles.min#{ext},styles.min.*#{ext}}"
ext = '.css'
dest = config.dist.app.client.styles.dir
fileName = path.basename config.fileName.styles.min, ext
src = path.join dest, "{#{fileName}#{ext},#{fileName}.*#{ext}}"
runTask src, dest, ext


@@ -1,14 +1,18 @@
module.exports = (gulp, config) ->
q = require 'q'
path = require 'path'
postcss = require 'postcss'
atImport = require 'postcss-import'

runTask = ->
defer = q.defer()
src = config.temp.client.styles.min.path
dest = config.temp.client.styles.dir
minFile = config.temp.client.styles.min.file
opts = root: config.dist.app.client.dir
defer = q.defer()
ext = '.css'
fileName = path.basename config.fileName.styles.min, ext
src = config.temp.client.styles.dir
src = path.join src, "{#{fileName}#{ext},#{fileName}.*#{ext}}"
dest = config.temp.client.styles.dir
minFile = config.temp.client.styles.min.file
opts = root: config.dist.app.client.dir

gulp.src src
.on 'data', (file) ->

0 comments on commit d020567

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