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.
This commit is contained in:
David Glasser
2015-03-05 15:11:18 -08:00
parent 905092d4b5
commit 36ff10c08c
3 changed files with 20 additions and 10 deletions

View File

@@ -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.

View File

@@ -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',

View File

@@ -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'