mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Uglify in //
This commit is contained in:
parent
722540f3be
commit
45e5e975f1
3 changed files with 76 additions and 16 deletions
|
@ -15,7 +15,6 @@ regJoin = (s) -> new RegExp(s.replace(/\//g, '[\\\/\\\\]'))
|
|||
|
||||
exports.config =
|
||||
|
||||
production: process.env.BRUNCH_ENV is 'production'
|
||||
paths:
|
||||
public: 'public'
|
||||
watched: [
|
||||
|
@ -33,13 +32,17 @@ exports.config =
|
|||
overrides:
|
||||
production:
|
||||
sourceMaps: 'absoluteUrl'
|
||||
onCompile: (files) ->
|
||||
# For some reason, production brunch produces two entries, the first of which is wrong:
|
||||
# //# sourceMappingURL=public/javascripts/app.js.map
|
||||
# //# sourceMappingURL=/javascripts/app.js.map
|
||||
# So we remove the ones that have public in them.
|
||||
exec = require('child_process').exec
|
||||
exec "perl -pi -e 's/\\/\\/# sourceMappingURL=public.*//g' public/javascripts/*.js"
|
||||
plugins:
|
||||
coffeelint:
|
||||
pattern: /\A\Z/
|
||||
afterBrunch: [
|
||||
"coffee scripts/minify.coffee",
|
||||
]
|
||||
fast:
|
||||
onCompile: (files) -> console.log "I feel the need, the need... for speed."
|
||||
plugins:
|
||||
coffeelint:
|
||||
pattern: /\A\Z/
|
||||
vagrant:
|
||||
watcher:
|
||||
usePolling: true
|
||||
|
@ -182,7 +185,6 @@ exports.config =
|
|||
plugins:
|
||||
coffeelint:
|
||||
pattern: /^app\/.*\.coffee$/
|
||||
# pattern: /^dne/ # use this pattern instead if you want to speed compilation
|
||||
options:
|
||||
line_endings:
|
||||
value: 'unix'
|
||||
|
@ -193,11 +195,6 @@ exports.config =
|
|||
level: 'ignore' # PyCharm can't just autostrip for .coffee, needed for .jade
|
||||
no_unnecessary_fat_arrows:
|
||||
level: 'ignore'
|
||||
uglify:
|
||||
mangle:
|
||||
except: ['require']
|
||||
output:
|
||||
semicolons: false
|
||||
sass:
|
||||
mode: 'native'
|
||||
allowCache: true
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
"test": "./node_modules/.bin/karma start",
|
||||
"predeploy": "echo Starting deployment--hold onto your butts.; echo Skipping brunch build --production",
|
||||
"postdeploy": "echo Deployed. Unclench.",
|
||||
"postinstall": "bower install && brunch build",
|
||||
"postinstall": "bower install && brunch build --env fast",
|
||||
"brunch": "brunch",
|
||||
"bower": "bower",
|
||||
"dev": "brunch watch --server",
|
||||
|
@ -82,6 +82,7 @@
|
|||
"winston": "0.6.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"after-brunch": "0.0.5",
|
||||
"assetsmanager-brunch": "^1.8.1",
|
||||
"auto-reload-brunch": "> 1.0 < 1.8",
|
||||
"bless-brunch": "https://github.com/ThomasConner/bless-brunch/tarball/master",
|
||||
|
@ -92,6 +93,7 @@
|
|||
"commonjs-require-definition": "0.2.0",
|
||||
"compressible": "~1.0.1",
|
||||
"css-brunch": "^1.7.0",
|
||||
"fs-extra": "^0.26.2",
|
||||
"jade-brunch": "1.7.5",
|
||||
"jasmine-node": "1.13.x",
|
||||
"jasmine-spec-reporter": "~0.3.0",
|
||||
|
@ -111,7 +113,7 @@
|
|||
"requirejs": "~2.1.10",
|
||||
"sass-brunch": "https://github.com/basicer/sass-brunch-bleeding/archive/1.9.1-bleeding.tar.gz",
|
||||
"telepath-brunch": "https://github.com/nwinter/telepath-brunch/tarball/master",
|
||||
"uglify-js-brunch": "^1.7.8"
|
||||
"uglify-js": "^2.5.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"webworker-threads": "~0.5.5"
|
||||
|
|
61
scripts/minify.coffee
Normal file
61
scripts/minify.coffee
Normal file
|
@ -0,0 +1,61 @@
|
|||
path = require 'path'
|
||||
fs = require 'fs-extra'
|
||||
_ = require 'lodash'
|
||||
async = require 'async'
|
||||
cores = require('os').cpus().length
|
||||
child_process = require 'child_process'
|
||||
|
||||
root = path.join(__dirname, '..', 'public','javascripts');
|
||||
dest = path.join(__dirname, '..', 'public','javascripts-min');
|
||||
|
||||
console.log root
|
||||
dirStack = [path.join(root)]
|
||||
files = []
|
||||
|
||||
while dirStack.length
|
||||
dir = dirStack.pop()
|
||||
contents = fs.readdirSync(dir)
|
||||
for file in contents
|
||||
fullPath = "#{dir}/#{file}"
|
||||
stat = fs.statSync(fullPath)
|
||||
if stat.isDirectory()
|
||||
dirStack.push(fullPath)
|
||||
else if /\.js$/.test(file)
|
||||
files.push fullPath.replace root + '/', ''
|
||||
|
||||
|
||||
jobs = _.map files, (file) ->
|
||||
(cb2) ->
|
||||
fpath = path.join(root, file)
|
||||
dpath = path.join(dest, file)
|
||||
smArgs = []
|
||||
|
||||
if fs.existsSync fpath + '.map'
|
||||
smArgs = [
|
||||
'--in-source-map', fpath + '.map',
|
||||
'--source-map', dpath + '.map',
|
||||
'--source-map-include-sources',
|
||||
'--source-map-url', '/javascripts/' + file.replace('/\\/g', '/') + '.map'
|
||||
]
|
||||
|
||||
args = [fpath, '-m', '-r', 'require' , '-b', 'beautify=false,semicolons=false'].concat smArgs, ['-o', dpath]
|
||||
async.waterfall [
|
||||
_.bind(fs.mkdirs, fs, path.dirname dpath),
|
||||
(last, cb) ->
|
||||
child = child_process.spawn 'uglifyjs', args, stdio:'inherit'
|
||||
child.on 'close', (code) ->
|
||||
if code == 0 then cb null
|
||||
else cb code
|
||||
child.on 'error', (err) ->
|
||||
cb err
|
||||
], cb2
|
||||
|
||||
async.parallelLimit jobs, cores, (err, res)->
|
||||
if err
|
||||
console.log "ERROR:", err
|
||||
else
|
||||
console.log "Done, minified " + jobs.length + " files."
|
||||
fs.renameSync(root, root + "-old")
|
||||
fs.renameSync(dest, root)
|
||||
fs.removeSync(root + "-old")
|
||||
|
Loading…
Reference in a new issue