From 36ff10c08cd2cbc4ae2295095d6340f88c5f8f83 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Thu, 5 Mar 2015 15:11:18 -0800 Subject: [PATCH] Keep minifiers out of built programs This breaks the path meteor-platform -> webapp -> boilerplate-generator -> spacebars-compiler -> minifiers which ended up shipping all of uglify with each built app, even though the code generated in boilerplate-generator is just eval'd without ever being shown to humans. Beautification still works on JS generated by templating (*.html), though. --- packages/spacebars-compiler/compiler.js | 17 +++++++++-------- packages/spacebars-compiler/package.js | 5 ++++- packages/templating/package.js | 8 +++++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/spacebars-compiler/compiler.js b/packages/spacebars-compiler/compiler.js index 9e819aa629..dc859be64a 100644 --- a/packages/spacebars-compiler/compiler.js +++ b/packages/spacebars-compiler/compiler.js @@ -90,14 +90,15 @@ SpacebarsCompiler.codeGen = function (parseTree, options) { }; SpacebarsCompiler._beautify = function (code) { - if (Package.minifiers && Package.minifiers.UglifyJSMinify) { - var result = UglifyJSMinify(code, - { fromString: true, - mangle: false, - compress: false, - output: { beautify: true, - indent_level: 2, - width: 80 } }); + if (Package.minifiers) { + var result = Package.minifiers.UglifyJSMinify( + code, + { fromString: true, + mangle: false, + compress: false, + output: { beautify: true, + indent_level: 2, + width: 80 } }); var output = result.code; // Uglify interprets our expression as a statement and may add a semicolon. // Strip trailing semicolon. diff --git a/packages/spacebars-compiler/package.js b/packages/spacebars-compiler/package.js index c5bc679ff9..4dac9cb016 100644 --- a/packages/spacebars-compiler/package.js +++ b/packages/spacebars-compiler/package.js @@ -11,7 +11,10 @@ Package.onUse(function (api) { api.use('blaze-tools'); api.use('underscore'); - api.use('minifiers', ['server']); + // The templating plugin will pull in minifiers, so that generated code will + // be beautified. But it's a weak dependency so that eg boilerplate-generator + // doesn't pull in minifiers. + api.use('minifiers', ['server'], { weak: true }); api.addFiles(['templatetag.js', 'optimizer.js', 'codegen.js', diff --git a/packages/templating/package.js b/packages/templating/package.js index 7ce2e09732..7fe25a7e5d 100644 --- a/packages/templating/package.js +++ b/packages/templating/package.js @@ -10,7 +10,13 @@ Package.describe({ Package.registerBuildPlugin({ name: "compileTemplates", - use: ['spacebars-compiler'], + // minifiers is a weak dependency of spacebars-compiler; adding it here + // ensures that the output is minified. (Having it as a weak dependency means + // that we don't ship uglify etc with built apps just because + // boilerplate-generator uses spacebars-compiler.) + // XXX maybe uglify should be applied by this plugin instead of via magic + // weak dependency. + use: ['minifiers', 'spacebars-compiler'], sources: [ 'plugin/html_scanner.js', 'plugin/compile-templates.js'