Skip to content

Commit

Permalink
Merge pull request #1059 from stealjs/tree-shaking2
Browse files Browse the repository at this point in the history
Disable client-side treeshaking when BuildOption is used
  • Loading branch information
matthewp committed Jul 31, 2018
2 parents c377ecd + 6410fb8 commit dbdc82f
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/assign_default_options.js
Expand Up @@ -44,6 +44,11 @@ module.exports = function(config, options){
throw new Error("bundlesPath has been removed. Use dest instead: http://stealjs.com/docs/steal-tools.BuildOptions.html");
}

// Tree-shaking
if(options.treeShaking === false) {
config.treeShaking = false;
}

// package.json!npm is now the default
if(!config.config && !config.configMain) {
config.configMain = "package.json!npm";
Expand Down
45 changes: 45 additions & 0 deletions test/tree_shaking_test.js
Expand Up @@ -179,6 +179,51 @@ describe("Tree-shaking", function(){
assert.equal(typeof dep.two, "function", "Included");
});
});

describe("With a multi-main project", function(){
var app;
before(function(done){
this.timeout(20000);
var base = path.join(__dirname, "treeshake", "multimain");
var config = {
config: path.join(base, "package.json!npm"),
main: [
"~/main1",
"~/main2"
]
};
var page = `prod1.html`;

rmdir(path.join(base, "dist"))
.then(function() {
return optimize(config, {
quiet: true,
minify: false,
treeShaking: false
});
})
.then(function() {
var close;
return open(path.join("test", "treeshake", "multimain", page))
.then(function(args) {
close = args.close;
browser = args.browser;
return find(browser, "globals");
})
.then(function(mod) {
app = mod;
close();
done();
});
})
.catch(done);
});

it("Doesn\'t tree shake modules", function(){
let Component = app.Component;
assert.equal(typeof Component, "function", "was not tree-shaken");
});
});
});

describe("Bundles", function() {
Expand Down
1 change: 1 addition & 0 deletions test/treeshake/multimain/es/lib-ajax.js
@@ -0,0 +1 @@
export {default} from "./lib/ajax";
1 change: 1 addition & 0 deletions test/treeshake/multimain/es/lib-component.js
@@ -0,0 +1 @@
export {default} from "./lib/component";
1 change: 1 addition & 0 deletions test/treeshake/multimain/es/lib-map.js
@@ -0,0 +1 @@
export {default} from "./lib/map";
6 changes: 6 additions & 0 deletions test/treeshake/multimain/es/lib/ajax.js
@@ -0,0 +1,6 @@

function ajax() {

}

module.exports = ajax;
6 changes: 6 additions & 0 deletions test/treeshake/multimain/es/lib/component.js
@@ -0,0 +1,6 @@

class Component {

}

module.exports = Component;
6 changes: 6 additions & 0 deletions test/treeshake/multimain/es/lib/map.js
@@ -0,0 +1,6 @@

class Map {

}

module.exports = Map;
2 changes: 2 additions & 0 deletions test/treeshake/multimain/lib-core.js
@@ -0,0 +1,2 @@
export { default as Component } from "./es/lib-component";
export { default as Map } from "./es/lib-map";
1 change: 1 addition & 0 deletions test/treeshake/multimain/lib-ecosystem.js
@@ -0,0 +1 @@
export { default as ajax } from "./es/lib-ajax";
2 changes: 2 additions & 0 deletions test/treeshake/multimain/lib.js
@@ -0,0 +1,2 @@
export * from "./lib-core.js";
export * from "./lib-ecosystem.js";
4 changes: 4 additions & 0 deletions test/treeshake/multimain/main1.js
@@ -0,0 +1,4 @@
import { Component } from "./lib";

window.globals = window.globals || {};
window.globals.Component = Component;
4 changes: 4 additions & 0 deletions test/treeshake/multimain/main2.js
@@ -0,0 +1,4 @@
import { Map } from "./lib";

window.globals = window.globals || {};
window.globals.Map = Map;
5 changes: 5 additions & 0 deletions test/treeshake/multimain/package.json
@@ -0,0 +1,5 @@
{
"name": "treeshake",
"main": "main.js",
"version": "1.0.0"
}
11 changes: 11 additions & 0 deletions test/treeshake/multimain/prod1.html
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

<script src="dist/bundles/treeshake/main1.js"></script>
</body>
</html>

0 comments on commit dbdc82f

Please sign in to comment.