Commit e0c3ae61 authored by XhmikosR's avatar XhmikosR
Browse files

Merge pull request #13151 from twbs/customizer-uglifyjs2

Customizer: switch to UglifyJS2
parents a69bc3bc 1267a9a0
Showing with 38 additions and 35 deletions
+38 -35
...@@ -276,8 +276,27 @@ window.onload = function () { // wait for load in a dumb way because B-0 ...@@ -276,8 +276,27 @@ window.onload = function () { // wait for load in a dumb way because B-0
return result return result
} }
function generateJavascript(preamble) { function uglify(js) {
var ast = UglifyJS.parse(js)
ast.figure_out_scope()
var compressor = UglifyJS.Compressor()
var compressedAst = ast.transform(compressor)
compressedAst.figure_out_scope()
compressedAst.compute_char_frequency()
compressedAst.mangle_names()
var stream = UglifyJS.OutputStream()
compressedAst.print(stream)
return stream.toString()
}
function generateJS(preamble) {
var $checked = $('#plugin-section input:checked') var $checked = $('#plugin-section input:checked')
var jqueryCheck = 'if (typeof jQuery === "undefined") { throw new Error("Bootstrap\'s JavaScript requires jQuery") }\n\n'
if (!$checked.length) return false if (!$checked.length) return false
var js = $checked var js = $checked
...@@ -285,9 +304,12 @@ window.onload = function () { // wait for load in a dumb way because B-0 ...@@ -285,9 +304,12 @@ window.onload = function () { // wait for load in a dumb way because B-0
.toArray() .toArray()
.join('\n') .join('\n')
preamble = cw + preamble
js = jqueryCheck + js
return { return {
'bootstrap.js': preamble + js, 'bootstrap.js': preamble + js,
'bootstrap.min.js': preamble + cw + uglify(js) 'bootstrap.min.js': preamble + uglify(js)
} }
} }
...@@ -351,7 +373,7 @@ window.onload = function () { // wait for load in a dumb way because B-0 ...@@ -351,7 +373,7 @@ window.onload = function () { // wait for load in a dumb way because B-0
' * Config saved to config.json and ' + gistUrl + '\n' + ' * Config saved to config.json and ' + gistUrl + '\n' +
' */\n' ' */\n'
generateZip(generateCSS(preamble), generateJavascript(preamble), generateFonts(), configJson, function (blob) { generateZip(generateCSS(preamble), generateJS(preamble), generateFonts(), configJson, function (blob) {
$compileBtn.removeAttr('disabled') $compileBtn.removeAttr('disabled')
saveAs(blob, 'bootstrap.zip') saveAs(blob, 'bootstrap.zip')
}) })
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment