You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Libraries that have both CommonJs and AMD definitions #333
I have a library that has the following definition:
(function (root, factory) {
if (typeof module === "object" && module.exports) {
// Node, or CommonJS-Like environments
module.exports = factory(require("lodash"), require("conduitjs"), this);
} else if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define(["lodash", "conduitjs"], function (_, Conduit) {
return factory(_, Conduit, root);
});
} else {
// Browser globals
root.postal = factory(root._, root.Conduit, root);
}
}(this, function (_, Conduit, global, undefined)
When WebPack detects these definitions, it includes both (webpack)/buildin/amd-options.js and (webpack)/buildin/module.js. I get that its doing this because both CommonJs and AMD are at play, but I don't get why they are needed in the first place given that WebPack supports these (with my normal modules) without the need for this.
Is it possible to tell the system, "try and just use AMD or CommonJS, but if you need to use both, thats ok"? It seems like the intelligent thing that webpack could do (note thats not to imply its easy).
@jhnns npm is strictly for CJS format, there might be modules that try to support other formats, but modules that doesn't support CJS doesn't make sense in npm, they're just invalid
Activity
agundermann commentedon Jul 1, 2014
Try with imports loader
From https://webpack.github.io/docs/shimming-modules.html#fixing-broken-module-styles
avanderhoorn commentedon Jul 1, 2014
Ok I'll give this a go. Whats the down side of doing this though? I'm guessing its on by default for a reason?
sokra commentedon Jul 1, 2014
It's not this code fragment that causes this modules to be included. This UMD code fragment compiles down to:
Try
--display-reasonsto show the reason of a module inclusion.(webpack)/buildin/amd-options.jsis included when you usedefine.amd.(webpack)/buildin/module.jsis included when you usemoduleBoth are pretty small modules.
avanderhoorn commentedon Jul 1, 2014
Great! I don't have a particularly big problem with it, just trying to understand how and why everything running/put together.
jhnns commentedon Jul 2, 2014
Since there will always be modules in your codebase which use AMD or CommonJS I think it's pretty common that both buildins end up in your bundle.
avanderhoorn commentedon Jul 2, 2014
Is it possible to tell the system, "try and just use AMD or CommonJS, but if you need to use both, thats ok"? It seems like the intelligent thing that webpack could do (note thats not to imply its easy).
nickdima commentedon Sep 10, 2014
I have the same problem with the EventEmitter2 NPM module.
Wouldn't be feasible to handle all NPM modules by default as commonjs modules?
This is the code I'm talking about:
https://github.com/asyncly/EventEmitter2/blob/master/lib/eventemitter2.js#L560
sokra commentedon Sep 10, 2014
Blame the module...
Here is a config that disables AMD for all node_modules:
jhnns commentedon Sep 12, 2014
That's not possible. There are AMD modules on npm.
medikoo commentedon Sep 15, 2014
@jhnns npm is strictly for CJS format, there might be modules that try to support other formats, but modules that doesn't support CJS doesn't make sense in npm, they're just invalid
sokra commentedon Sep 15, 2014
https://github.com/mozilla/source-map is in AMD, but with
amdefine. webpack will thread it as AMD.perf(css): drop what a declaration, a slot or a query already says
perf(css): drop what a declaration, a slot or a query already says
perf(css): drop what a declaration, a slot or a query already says
perf(css): drop what a declaration, a slot or a query already says
perf(css): drop what a declaration, a slot or a query already says (#…