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
CommonJS builds, output.exports = 'defualt', and ignoring extraneous named-exports #3345
Comments
What is the point of ignoring named exports. Can you just not export those classes? |
I'm not sure what you mean — I am exporting them? Or do you mean something else by 'export?' (= |
I think this proposal is a good idea, I'd go even further and say that a value for Consider the following library: export default class MainClass {
doSomething() { ... }
}
export function utilityFunction() { ... } Now to import this you write: // module
import MyLib from 'my-lib'
let instance = new MyLib()
// commonjs
const MyLib = require('my-lib').default
let instance = new MyLib()
// global
let instance = new MyLib.default() Now instead with the default assigned as the module root you could write: // module
import MyLib from 'my-lib'
let instance = new MyLib()
// commonjs
const MyLib = require('my-lib')
let instance = new MyLib()
// global
let instance = new MyLib() Notice how the There is ways to work around this but none that isn't "worse practice" than using default exports. I could assign my utility function to |
This is default rollup output when you do not have named exports. With named exports it's not clear how interop should be handled. And look with named only exports you have consistent imports
|
That's probably a better workaround with the current bundler 👍
It's clear, just not safe if you're for some reason exporting numbers as your default :) That's why I suggested to call the option |
Could it also be another output toggle, like As it sits currently I'll probably have to make a separate entry point with a single export, just to get around this. |
Hi, all, you can solve this issue by using: |
Expected Behavior / Situation
I've got an ES6 module that exports both several intermediate values and constructors, and a
default
value that's a few publicly-documented selections thereof:I expected that my Rollup ESM-build would behave the same (including both individual-exports, if the consumer wished to import them; as well as the actual "function bag" that's the public API of available classes and functions); while Rollup's CJS-build would only include the "function bag" defined as the default-value.
My configuration looks something like this:
Actual Behavior / Situation
The
'esm'
build behaves as expected, but trying to build the'cjs'
build as above produces either — withexports: 'default'
:… or without:
Modification Proposal
I propose, for
format: 'cjs'
builds, either thatoutput.exports: 'default'
completely ignore named-exports as long as a default-export is provided; or a new value foroutput.exports
be provided that explicitly ignores named-exports as long as a default-export is provided.Hope this made sense! Rollup is exactly what I needed to solve a major packaging problem of mine, and I'm super-happy that it exists; keep up the good maintenance work. <3
The text was updated successfully, but these errors were encountered: