diff --git a/minifier.js b/minifier.js index 3cd1c81ff8..bca79e68f1 100644 --- a/minifier.js +++ b/minifier.js @@ -30,9 +30,10 @@ Minifier.js.minify = function (scripts, minify, callback) { process.on('message', function(payload) { switch(payload.action) { case 'js': - Minifier.js.minify(payload.scripts, payload.minify, function(minified) { + Minifier.js.minify(payload.scripts, payload.minify, function(minified/*, sourceMap*/) { process.send({ type: 'end', + // sourceMap: sourceMap, minified: minified }); }); @@ -41,8 +42,11 @@ process.on('message', function(payload) { }); function minifyScripts(scripts, callback) { + // The portions of code involving the source map are commented out as they're broken in UglifyJS2 + // Follow along here: https://github.com/mishoo/UglifyJS2/issues/700 try { var minified = uglifyjs.minify(scripts, { + // outSourceMap: "nodebb.min.js.map", compress: false }), hasher = crypto.createHash('md5'), @@ -56,7 +60,7 @@ function minifyScripts(scripts, callback) { payload: hash.slice(0, 8) }); - callback(minified.code); + callback(minified.code/*, minified.map*/); } catch(err) { process.send({ type: 'error', diff --git a/package.json b/package.json index d6c37b900e..b84816767f 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "string": "^3.0.0", "templates.js": "^0.2.6", "touch": "0.0.3", - "uglify-js": "git+https://github.com/julianlam/UglifyJS2.git", + "uglify-js": "^2.4.23", "underscore": "~1.8.3", "underscore.deep": "^0.5.1", "validator": "^3.30.0", diff --git a/src/meta/js.js b/src/meta/js.js index 0384e8d36d..020611e7ce 100644 --- a/src/meta/js.js +++ b/src/meta/js.js @@ -141,6 +141,7 @@ module.exports = function(Meta) { switch(message.type) { case 'end': Meta.js.cache = message.minified; + Meta.js.map = message.sourceMap; onComplete(); break; case 'hash': diff --git a/src/routes/meta.js b/src/routes/meta.js index e028adf63d..03cf1cde24 100644 --- a/src/routes/meta.js +++ b/src/routes/meta.js @@ -8,6 +8,16 @@ function sendMinifiedJS(req, res, next) { res.type('text/javascript').send(meta.js.cache); } +// The portions of code involving the source map are commented out as they're broken in UglifyJS2 +// Follow along here: https://github.com/mishoo/UglifyJS2/issues/700 +// function sendJSSourceMap(req, res) { +// if (meta.js.hasOwnProperty('map')) { +// res.type('application/json').send(meta.js.map); +// } else { +// res.redirect(404); +// } +// }; + function sendStylesheet(req, res, next) { res.type('text/css').status(200).send(meta.css.cache); } @@ -20,6 +30,7 @@ module.exports = function(app, middleware, controllers) { app.get('/stylesheet.css', middleware.addExpiresHeaders, sendStylesheet); app.get('/admin.css', middleware.addExpiresHeaders, sendACPStylesheet); app.get('/nodebb.min.js', middleware.addExpiresHeaders, sendMinifiedJS); + // app.get('/nodebb.min.js.map', middleware.addExpiresHeaders, sendJSSourceMap); app.get('/sitemap.xml', controllers.sitemap); app.get('/robots.txt', controllers.robots); app.get('/css/previews/:theme', controllers.admin.themes.get);