Skip to content

Commit

Permalink
Do not minify development bundles by default
Browse files Browse the repository at this point in the history
- Turning off minification speeds up bundle creation
- Fixes an issue with incorrect module detection caused by
  minified dev bundles (steal-tools appends a module that
  preloads package.json files to prevent requests of the bundled
  modules, if the package.json files include glob patterns it will
  break Steal.js module detection, only happens when the bundle
  is minified)

Closes steal/1227
  • Loading branch information
m-mujica committed Dec 9, 2017
1 parent d177a6e commit 0516719
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module.exports = function(config, options) {

var isDestProvided = !!options.dest;

// minification is on by default
options.minify = options.minify == null ? true : options.minify;
// minification is disabled by default
options.minify = options.minify == null ? false : options.minify;

try {
options = assignDefaultOptions(config, options);
Expand Down
57 changes: 41 additions & 16 deletions test/dev_bundle_build_test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
var _ = require("lodash");
var path = require("path");
var fs = require("fs-extra");
var assert = require("assert");
var assign = require("lodash/assign");
var denodeify = require("pdenodeify");
var testHelpers = require("./helpers");
var isUndefined = require("lodash/isUndefined");
var escapeRegExp = require("lodash/escapeRegExp");
var devBundleBuild = require("../lib/build/bundle");

var open = testHelpers.popen;
var find = testHelpers.pfind;
var readFile = denodeify(fs.readFile);
var rmdir = denodeify(require("rimraf"));

describe("dev bundle build", function() {
this.timeout(5000);

var baseOptions = {
quiet: true,
minify: false
quiet: true
};

it("should not be minified by default", function() {
var config = {
main: "bundle",
config: path.join(__dirname, "bundle", "stealconfig.js"),
};

var bundlePath = path.join(__dirname, "bundle", "dev-bundle.js");

return devBundleBuild(config, baseOptions)
.then(function() {
return readFile(bundlePath);
})
.then(function(contents) {
// comments are removed during minification
var rx = new RegExp(escapeRegExp("/*[system-bundles-config]*/"));
var rx2 = new RegExp(escapeRegExp("/*stealconfig.js*/"));

assert(rx.test(contents), "bundle should not be minified");
assert(rx2.test(contents), "bundle should not be minified");
})
.then(function() {
return rmdir(bundlePath);
});
});

it("should work with defaults", function() {
var config = {
config: path.join(__dirname, "npm", "package.json!npm")
Expand Down Expand Up @@ -52,7 +77,7 @@ describe("dev bundle build", function() {
config: path.join(__dirname, "bundle", "stealconfig.js"),
};

var options = _.assign({}, baseOptions, {
var options = assign({}, baseOptions, {
filter: "**/*"
});

Expand All @@ -74,7 +99,7 @@ describe("dev bundle build", function() {
config: path.join(__dirname, "bundle", "stealconfig.js"),
};

var options = _.assign({}, baseOptions, {
var options = assign({}, baseOptions, {
filter: [
"**/*.js",
"!dep_a_b.js",
Expand All @@ -88,8 +113,8 @@ describe("dev bundle build", function() {
.then(function(buildResult) {
var graph = buildResult.graph;

assert(_.isUndefined(graph['dep_a_b']), "should not be in the graph");
assert(_.isUndefined(graph['dep_all']), "should not be in the graph");
assert(isUndefined(graph['dep_a_b']), "should not be in the graph");
assert(isUndefined(graph['dep_all']), "should not be in the graph");
})
.then(function() {
return rmdir(bundlePath);
Expand All @@ -102,7 +127,7 @@ describe("dev bundle build", function() {
config: path.join(__dirname, "bundle", "stealconfig.js"),
};

var options = _.assign({}, baseOptions, {
var options = assign({}, baseOptions, {
filter: "**/*",
dest: "folder/"
});
Expand All @@ -125,7 +150,7 @@ describe("dev bundle build", function() {
config: path.join(__dirname, "plugins", "config.js")
};

var options = _.assign({}, baseOptions, {
var options = assign({}, baseOptions, {
filter: "**/*"
});

Expand All @@ -137,7 +162,7 @@ describe("dev bundle build", function() {
})
.then(function(contents) {
var empty = "define('plug', [], function(){ return {}; });";
var regexp = new RegExp(_.escapeRegExp(empty));
var regexp = new RegExp(escapeRegExp(empty));

assert(!regexp.test(contents), "plugin code should be included");
})
Expand All @@ -151,7 +176,7 @@ describe("dev bundle build", function() {
config: path.join(__dirname, "npm", "package.json!npm")
};

var options = _.assign({}, baseOptions, {
var options = assign({}, baseOptions, {
filter: "node_modules/**/*" // only bundle npm deps
});

Expand All @@ -167,7 +192,7 @@ describe("dev bundle build", function() {
})
.then(function(contents) {
var nodeName = "[steal-add-npm-packages]";
var regexp = new RegExp(_.escapeRegExp(nodeName));
var regexp = new RegExp(escapeRegExp(nodeName));

assert(regexp.test(contents), "bundle should include npm node");
})
Expand All @@ -181,7 +206,7 @@ describe("dev bundle build", function() {
config: path.join(__dirname, "npm", "package.json!npm")
};

var options = _.assign({}, baseOptions, {
var options = assign({}, baseOptions, {
filter: [ "node_modules/**/*", "package.json" ]
});

Expand All @@ -197,7 +222,7 @@ describe("dev bundle build", function() {
})
.then(function(contents) {
var nodeName = "[steal-add-npm-packages]";
var regexp = new RegExp(_.escapeRegExp(nodeName));
var regexp = new RegExp(escapeRegExp(nodeName));

assert(!regexp.test(contents), "bundle should include npm node");
})
Expand All @@ -219,7 +244,7 @@ describe("dev bundle build", function() {
})
.then(function(contents) {
var nodeName = "it worked";
var regexp = new RegExp(_.escapeRegExp(nodeName));
var regexp = new RegExp(escapeRegExp(nodeName));

assert(regexp.test(contents), "bundle should dev code");
})
Expand Down

0 comments on commit 0516719

Please sign in to comment.