-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
fix #334 add esm export #368
Conversation
Can you please add a change log entry about this? |
Bundle size report: Size Change: 0 B
ℹ️ View DetailsNo major changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nitpicking...
@@ -19,6 +19,7 @@ | |||
- ** Breaking Change ** removed `baseApiUrl` as it was used only for mapbox related urls | |||
- Added redraw function to map (#206) | |||
- *...Add new stuff here...* | |||
- Add module entrypoint for ESM (#334) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong place, should be one line upwards.
this has been fixed. |
With CommonJS syntax, we can default export an object and its properties are found in the named exports. // src/index.ts
const exported = {
Map,
NavigationControl,
//...
};
export default exported; with rollup became // dist/maplibre-gl.js
module.exports = {
Map,
NavigationControl,
// ...
}; in your app import maplibregl from "maplibre-gl"; // ok
import { Map } from "maplibre-gl"; // ok with ESM we must explicitly define the named export // src/index.ts
export { Map } from './ui/map';
export { NavigationControl } from './ui/control/navigation_control';
export default { Map, NavigationControl };
//... import maplibregl from "maplibre-gl"; // ok
import { Map } from "maplibre-gl"; // ok I unfortunately do not really know how to operate with the getters setters in |
The When importing with node an "exports" field should be added. Something like this: "main": "./dist/maplibre-gl.cjs",
"exports": {
"import": "./dist/maplibre-gl.module.js",
"require": "./dist/maplibre-gl.cjs"
}, |
I totally agree with you @anajavi. |
I think that by explicitly specifying an esm export without named exports you lose flexibility. I therefore close this request and propose a simpler alternative #635. |
Can you guys check my poposed fixed in the following comment: |
in order to continue the discussion #334
In my opinion, there is an issue with the default export of the package.
According to the
package.json
The maplibre-gl package is using the ESM modules but the output is an UMD file.
If I build an app who follows the esm specification and who wants to import maplibre-gl
The application will apply the esm resolver algorithm
the application will retrieve the
dist/maplibre-gl.js
file but will consider it to be an esm file.I suggest adding a module entry in the
package.json
who provides a esm export. By keeping the current main entry, we have a way to easily implement maplibre and with the module entry we allow bundlers (like ViteJS) following the esm specification to find the right export format.What do you think about that ?
I'm not talking about the isomorphic side dealt with at the end of the discussion #334 which is another discussion.