Skip to content
Permalink
Browse files

fix(cache busting): by changing libs and bower_components css urls to…

… absolute for the prod build
  • Loading branch information
jyounce committed Jul 28, 2015
1 parent 2bf7465 commit dcd845a5dd1f1dfc03795ba483a253941b5764b5
@@ -5,90 +5,91 @@
module.exports = (gulp, config) ->
# browser
# =======
bs = require("#{config.req.tasks}/browser/browser-sync") gulp, config # browser-sync
require("#{config.req.tasks}/browser/open-browser") gulp, config # open-browser
bs = require("#{config.req.tasks}/browser/browser-sync") gulp, config # browser-sync
require("#{config.req.tasks}/browser/open-browser") gulp, config # open-browser

# build
# =====
require("#{config.req.tasks}/build/build-angular-modules") gulp, config # build-angular-modules
require("#{config.req.tasks}/build/build-bower-json") gulp, config # build-bower-json
require("#{config.req.tasks}/build/build-config") gulp, config # build-config
require("#{config.req.tasks}/build/build-files") gulp, config # build-files
require("#{config.req.tasks}/build/build-prod-files") gulp, config # build-prod-files
require("#{config.req.tasks}/build/build-prod-files-blueprint") gulp, config # build-prod-files-blueprint
require("#{config.req.tasks}/build/build-spa") gulp, config # build-spa
require("#{config.req.tasks}/build/build-angular-modules") gulp, config # build-angular-modules
require("#{config.req.tasks}/build/build-bower-json") gulp, config # build-bower-json
require("#{config.req.tasks}/build/build-config") gulp, config # build-config
require("#{config.req.tasks}/build/build-files") gulp, config # build-files
require("#{config.req.tasks}/build/build-prod-files") gulp, config # build-prod-files
require("#{config.req.tasks}/build/build-prod-files-blueprint") gulp, config # build-prod-files-blueprint
require("#{config.req.tasks}/build/build-spa") gulp, config # build-spa

# clean
# =====
require("#{config.req.tasks}/clean/clean-config") gulp, config # clean-config
require("#{config.req.tasks}/clean/clean-dist") gulp, config # clean-dist
require("#{config.req.tasks}/clean/clean-files") gulp, config # clean-files
require("#{config.req.tasks}/clean/cleanup-client") gulp, config # cleanup-client
require("#{config.req.tasks}/clean/clean-config") gulp, config # clean-config
require("#{config.req.tasks}/clean/clean-dist") gulp, config # clean-dist
require("#{config.req.tasks}/clean/clean-files") gulp, config # clean-files
require("#{config.req.tasks}/clean/cleanup-client") gulp, config # cleanup-client

# common
# ======
require("#{config.req.tasks}/common") gulp, config # common
require("#{config.req.tasks}/common") gulp, config # common

# compile
# =======
require("#{config.req.tasks}/compile/coffee") gulp, config # coffee
require("#{config.req.tasks}/compile/es6") gulp, config # es6
require("#{config.req.tasks}/compile/less") gulp, config # less
require("#{config.req.tasks}/compile/coffee") gulp, config # coffee
require("#{config.req.tasks}/compile/es6") gulp, config # es6
require("#{config.req.tasks}/compile/less") gulp, config # less

# config
# ======
require("#{config.req.tasks}/config/update-config") gulp, config # update-config
require("#{config.req.tasks}/config/update-config") gulp, config # update-config

# copy
# ====
require("#{config.req.tasks}/copy/copy-bower_components") gulp, config # copy-bower_components
require("#{config.req.tasks}/copy/copy-css") gulp, config # copy-css
require("#{config.req.tasks}/copy/copy-html") gulp, config # copy-html
require("#{config.req.tasks}/copy/copy-images") gulp, config # copy-images
require("#{config.req.tasks}/copy/copy-js") gulp, config # copy-js
require("#{config.req.tasks}/copy/copy-libs") gulp, config # copy-libs
require("#{config.req.tasks}/copy/copy-server-config") gulp, config # copy-server-config
require("#{config.req.tasks}/copy/copy-server-node_modules") gulp, config # copy-server-node_modules
require("#{config.req.tasks}/copy/copy-views") gulp, config # copy-views
require("#{config.req.tasks}/copy/copy-bower_components") gulp, config # copy-bower_components
require("#{config.req.tasks}/copy/copy-css") gulp, config # copy-css
require("#{config.req.tasks}/copy/copy-html") gulp, config # copy-html
require("#{config.req.tasks}/copy/copy-images") gulp, config # copy-images
require("#{config.req.tasks}/copy/copy-js") gulp, config # copy-js
require("#{config.req.tasks}/copy/copy-libs") gulp, config # copy-libs
require("#{config.req.tasks}/copy/copy-server-config") gulp, config # copy-server-config
require("#{config.req.tasks}/copy/copy-server-node_modules") gulp, config # copy-server-node_modules
require("#{config.req.tasks}/copy/copy-views") gulp, config # copy-views

# manage
# ======
require("#{config.req.tasks}/manage/bower") gulp, config # bower
require("#{config.req.tasks}/manage/bower") gulp, config # bower

# minify
# ======
require("#{config.req.tasks}/minify/cache-bust") gulp, config # cache-bust
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
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
require("#{config.req.tasks}/minify/minify-spa") gulp, config # minify-spa
require("#{config.req.tasks}/minify/template-cache") gulp, config # template-cache
require("#{config.req.tasks}/minify/cache-bust") gulp, config # cache-bust
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
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
require("#{config.req.tasks}/minify/minify-spa") gulp, config # minify-spa
require("#{config.req.tasks}/minify/relative-to-absolute-css-urls") gulp, config # relative-to-absolute-css-urls
require("#{config.req.tasks}/minify/template-cache") gulp, config # template-cache

# server
# ======
require("#{config.req.tasks}/server/start-server") gulp, config # start-server
require("#{config.req.tasks}/server/spawn-server") gulp, config # spawn-server
require("#{config.req.tasks}/server/nodemon") gulp, config, bs # nodemon
require("#{config.req.tasks}/server/start-server") gulp, config # start-server
require("#{config.req.tasks}/server/spawn-server") gulp, config # spawn-server
require("#{config.req.tasks}/server/nodemon") gulp, config, bs # nodemon

# test
# ====
require("#{config.req.tasks}/test/build-inject-angular-mocks") gulp, config # build-inject-angular-mocks
require("#{config.req.tasks}/test/build-test-files") gulp, config # build-test-files
require("#{config.req.tasks}/test/clean-rb-test-src") gulp, config # clean-rb-test-src
require("#{config.req.tasks}/test/clean-test-dist") gulp, config # clean-test-dist
require("#{config.req.tasks}/test/common-test") gulp, config # common-test
require("#{config.req.tasks}/test/copy-angular-mocks") gulp, config # copy-angular-mocks
require("#{config.req.tasks}/test/copy-tests") gulp, config # copy-tests
require("#{config.req.tasks}/test/run-tests") gulp, config # run-tests
require("#{config.req.tasks}/test/build-inject-angular-mocks") gulp, config # build-inject-angular-mocks
require("#{config.req.tasks}/test/build-test-files") gulp, config # build-test-files
require("#{config.req.tasks}/test/clean-rb-test-src") gulp, config # clean-rb-test-src
require("#{config.req.tasks}/test/clean-test-dist") gulp, config # clean-test-dist
require("#{config.req.tasks}/test/common-test") gulp, config # common-test
require("#{config.req.tasks}/test/copy-angular-mocks") gulp, config # copy-angular-mocks
require("#{config.req.tasks}/test/copy-tests") gulp, config # copy-tests
require("#{config.req.tasks}/test/run-tests") gulp, config # run-tests

# watch
# =====
require("#{config.req.tasks}/watch/watch") gulp, config, bs # watch
require("#{config.req.tasks}/watch/watch-build-spa") gulp, config # watch-build-spa
require("#{config.req.tasks}/watch/watch") gulp, config, bs # watch
require("#{config.req.tasks}/watch/watch-build-spa") gulp, config # watch-build-spa


@@ -2,7 +2,7 @@ module.exports = (gulp, config) ->
q = require 'q'
del = require 'del'
path = require 'path'
Bust = require 'gulp-cachebust'
Bust = require 'gulp-cachebust' # might try gulp-bust
promiseHelp = require "#{config.req.helpers}/promise"
unstampedPaths = []
bustOpts =
@@ -5,6 +5,7 @@ module.exports = (gulp, config) ->
# =============
gulp.task "#{config.rb.prefix.task}minify-client", (cb) ->
gulpSequence(
"#{config.rb.prefix.task}relative-to-absolute-css-urls"
[
"#{config.rb.prefix.task}minify-css"
"#{config.rb.prefix.task}minify-html"
@@ -0,0 +1,65 @@
module.exports = (gulp, config) ->
q = require 'q'
path = require 'path'
pathHelp = require "#{config.req.helpers}/path"
urlRegex = /url\s*\(\s*['"]?([^\/].*?)['"]?\s*\)/g

# helpers
# =======
# replace relative urls with absolute urls
replaceCssUrls = (css, fileDir, clientDist) ->
css = css.replace urlRegex, (match, urlPath) ->
first = urlPath[0]
second = urlPath[1]
first2 = first + second
isExternal = urlPath.toLowerCase().indexOf('//') isnt -1 # like from http
if first2 isnt "'/" and first2 isnt '"/' and not isExternal
_path = path.resolve fileDir, urlPath
_path = pathHelp.format _path
_path = _path.replace clientDist, ''
_path = "#{_path}"
else
_path = urlPath
url = _path.replace(/'/g,'').replace(/"/g,'')
url = "url('#{url}')"
url
css

# tasks
# =====
cssUrlSwap = (appOrRb, type, glob='css') ->
defer = q.defer()
src = config.glob.dist[appOrRb].client[type][glob]
dest = config.dist[appOrRb].client[type].dir
clientDist = path.join config.app.dir, config.dist.app.client.dir
clientDist = pathHelp.format clientDist
gulp.src src
.on 'data', (file) ->
return if file.isNull()
css = file.contents.toString()
fileDir = path.dirname file.path
fileDir = pathHelp.format fileDir
css = replaceCssUrls css, fileDir, clientDist
file.contents = new Buffer css
.pipe gulp.dest dest
.on 'end', ->
defer.resolve()
defer.promise

runTasks = ->
defer = q.defer()
q.all([
cssUrlSwap 'rb', 'bower'
cssUrlSwap 'rb', 'libs'
cssUrlSwap 'rb', 'styles', 'all'
cssUrlSwap 'app', 'bower'
cssUrlSwap 'app', 'libs'
]).done ->
console.log 'changed libs and bower_components css urls from relative to absolute'.yellow
defer.resolve()
defer.promise

# register task
# =============
gulp.task "#{config.rb.prefix.task}relative-to-absolute-css-urls", ->
runTasks()

0 comments on commit dcd845a

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