Skip to content

Commit

Permalink
Merge pull request #1081 from stealjs/se
Browse files Browse the repository at this point in the history
Make side-effectual imports work with globals
  • Loading branch information
matthewp committed Oct 4, 2018
2 parents f4b9e49 + 1793329 commit e508453
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/graph/treeshake.js
Expand Up @@ -152,7 +152,11 @@ function loadFromGraph(getNode) {
}

function sideEffectualModule(node) {
return node && node.load.metadata.buildType === "css";
if(node) {
let md = node.load.metadata;
return md.buildType === "css" || md.format === "global";
}
return false;
}

function transpile(getNode, data) {
Expand Down
4 changes: 3 additions & 1 deletion test/tree_shaking_test.js
Expand Up @@ -92,7 +92,9 @@ describe("Tree-shaking", function(){
describe("import 'mod'", function(){
it("Includes modules imported for side-effects", function(){
assert.equal(browser.window.DEP3_SIDE_EFFECT, true,
"Includes a module with needed side effects.");
"Includes an ES module with needed side effects.");
assert.equal(browser.window.DEP3_SIDE_EFFECT2, true,
"Includes a global module with needed side effects.");
});

it("Works when the dependency is CSS", function(){
Expand Down
1 change: 1 addition & 0 deletions test/treeshake/basics/main.js
Expand Up @@ -12,6 +12,7 @@ import steal from "@steal";

// Importing a module for its side effects
import "dep3";
import "dep3/global";

// CSS
import "./styles.css";
Expand Down
5 changes: 5 additions & 0 deletions test/treeshake/basics/node_modules/dep3/global.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e508453

Please sign in to comment.