Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make side-effectual imports work with globals #1081

Merged
merged 1 commit into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/graph/treeshake.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.