Skip to content

Commit

Permalink
Merge pull request #8250 from Aladdin-ADD/patch-3
Browse files Browse the repository at this point in the history
fix: disable ProvidePlugin for javascript/esm (fixes #7032)
  • Loading branch information
sokra committed Nov 5, 2018
2 parents 0293c3a + 770edef commit 355590e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/ProvidePlugin.js
Expand Up @@ -76,9 +76,8 @@ class ProvidePlugin {
normalModuleFactory.hooks.parser
.for("javascript/dynamic")
.tap("ProvidePlugin", handler);
normalModuleFactory.hooks.parser
.for("javascript/esm")
.tap("ProvidePlugin", handler);

// Disable ProvidePlugin for javascript/esm, see https://github.com/webpack/webpack/issues/7032
}
);
}
Expand Down
3 changes: 3 additions & 0 deletions test/configCases/plugins/provide-plugin/foo.mjs
@@ -0,0 +1,3 @@
export default function foo() {
return typeof esm;
}
5 changes: 5 additions & 0 deletions test/configCases/plugins/provide-plugin/index.js
Expand Up @@ -56,3 +56,8 @@ it("should provide ES2015 modules", function() {
expect((es2015_alias)).toBe("ECMAScript Harmony");
expect((es2015_year)).toBe(2015);
});

it("should not provide for mjs", function(){
var foo = require("./foo.mjs").default;
expect(foo()).toBe("undefined");
});
3 changes: 2 additions & 1 deletion test/configCases/plugins/provide-plugin/webpack.config.js
Expand Up @@ -10,7 +10,8 @@ module.exports = {
es2015_name: ["./harmony", "default"],
es2015_alias: ["./harmony", "alias"],
es2015_year: ["./harmony", "year"],
"this.aaa": "./aaa"
"this.aaa": "./aaa",
esm: "fail"
})
]
};

0 comments on commit 355590e

Please sign in to comment.