Skip to content

Commit

Permalink
Merge pull request #1048 from stealjs/shake-dev-bundles
Browse files Browse the repository at this point in the history
Prevent client-side tree shaking of dev bundles
  • Loading branch information
matthewp committed Jul 23, 2018
2 parents f427e3d + 4b7fbb0 commit 079db1e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/build/bundle.js
Expand Up @@ -11,7 +11,7 @@ var createWriteStream = require("../bundle/write_bundles").createWriteStream;
var createBundleGraphStream = require("../graph/make_graph_with_bundles")
.createBundleGraphStream;

module.exports = function(config, options) {
module.exports = function(cfg, options) {
// Use the build-development environment.
if (!options) options = {};

Expand All @@ -20,6 +20,9 @@ module.exports = function(config, options) {
// minification is disabled by default
options.minify = options.minify == null ? false : options.minify;

// tree shaking is disabled.
var config = Object.assign({ treeShaking: false }, cfg);

try {
options = assignDefaultOptions(config, options);
} catch(err) {
Expand Down
37 changes: 37 additions & 0 deletions test/dev_bundle_build_test.js
Expand Up @@ -412,4 +412,41 @@ describe("dev bundle build", function() {
.then(clean)
.catch(clean);
});

it("Doesn't tree shake dependencies", function(done) {
var dir = path.join(__dirname, "treeshake", "basics");
var devBundlePath = path.join(dir, "dev-bundle.js");

var config = {
config: path.join(dir, "package.json!npm")
};

var options = assign({}, baseOptions, {
minify: false,
filter: ["node_modules/**/*", "package.json"] // only bundle npm deps
});

var clean = function(err) {
rmdir(devBundlePath).then(function() {
done(err);
});
};

devBundleBuild(config, options)
.then(function() {
return open("test/treeshake/basics/dev.html");
})
.then(function(p) {
return find(p.browser, "APP").then(function(){
return p.browser.window;
})
})
.then(function(window){
var steal = window.steal;
var canConnect = steal.loader.get("can-connect@1.0.0#main");
assert.ok(canConnect, "Not tree shaken");
})
.then(clean)
.catch(clean);
});
});
22 changes: 22 additions & 0 deletions test/treeshake/basics/dev.html
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Development bundles and tree shaking</title>
</head>
<body>
<script
src="../../../node_modules/steal/steal.js"
base-url="."
config-main="package.json!npm"
dev-bundle
main
>
import app from "treeshake";

window.APP = { app };
</script>
</body>
</html>

0 comments on commit 079db1e

Please sign in to comment.