-
-
Notifications
You must be signed in to change notification settings - Fork 256
Export an ES Module instead of CommonJS module #99
Conversation
Since webpack v2, it's better to use ES modules. Note that this is incompatible with webpack v1, so it should be released as a major version.
Shouldn't this be behind a loader option that defaults to the
|
@jskrzypek Could you explain a use case for this? If you're making a library it wouldn't matter what export type you use here. |
It matters because different languages transpile to different import statements, for example TypeScript. if you have |
I would also prefer this to be an option, no need for a major release IMO. |
You can also patch this with a custom loader relatively easily export default function (content) {
if (this.cacheable) this.cacheable();
return `
Object.defineProperty(exports, "__esModule", { value: true });
${content.replace(/^module\.exports =/, 'exports.default =')}
`;
} |
@alexgorbatchev fwiw you can use the |
@jskrzypek thanks for the tip! I just read up on this option and tried it. Unfortunately it didn't achieve the same effect, the doc says it only affects type checking. The loader I posted above seems to be the best solution (that I have found so far). |
One of the uae cases is is you want to name the exported contents so as to not use the default export (which sometimes causes headches for anyone handling your lib with other bundlers) In that case you could do something like this:
Since the point of this whole PR is that we're doing things "better", it's probably better to use named exports since the CommonJS spec doesn't even allow for default/unnamed exports, strictly speaking |
@alexgorbatchev interesting it was largely undocumented last I checked... I guess i should read up on it again |
Will be done via |
So for typescript have to do: import myFont = require('./fonts/my-font.otf')
isn't this going to change? |
@whitecolor Unfortunately It's not possible to export a ES2015 Module atm bc of the |
Since webpack v2, it's better to use ES modules. Note that this is incompatible with webpack v1, so it should be released as a major version.
Fixes #96.