-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Allow import of non-js files via exports
in package.json
#10711
Conversation
Thanks for the pull request @ggetz!
Reviewers, don't forget to make sure that:
|
@ggetz Could you provide an example of an import for a CSS file, for example, using this subpath pattern? I'm trying it in |
@sanjeetsuhag From the built version, the import would be |
I ran the following commands in the npm install
npm run release # To generate the Build/Cesium folder
npm link In
I get the following error:
|
In resolve: {
- alias: {
- cesium: path.resolve(__dirname, cesiumSource)
- },
+ fallback: { "https": false, "zlib": false, "http": false },
mainFiles: ['index', 'Cesium']
}, The |
@ggetz Alright, that cleared it up. Everything works as expected! Just need to merge in |
Thanks @sanjeetsuhag, should be ready to go! |
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.
Thanks @ggetz!
Did you test the part that's supposed to disallow js imports (with null value)? The Node docs say the entries there are evaluated in order, so if a js path hits the general wildcard first, I think it would use that and never reach the null. |
Yes, I was not able to import JS files with this configuration. For example, importing from |
Yeah that's pretty confusing, I may double check on the Node tracker if they want to specify an order of operations / precedence -- the docs definitely don't make it explict. Thanks for tracking it down! |
Fixes #9212
This allows users to import non-JS files from the CesiumJS package, including CSS files and images, using subpath patterns, available in NodeJS 12 and above. I explicitly disallowed absolute path imports for JS files as it eliminates ambiguity about importing modules from the default (
"cesium"
), and avoids a situation where typescript looks for co-located definition files instead of at the maintypes
location.I allow both
Source
andBuild
exports as it allows users some flexibility based on their build tooling: Some may want to use the pre-bundled and minified CSS from the build folder (as recommended in our Quickstart Guide), while others may prefer handling the bundling and magnification separately.This can be tested using a bundler such as Rollup or Webpack, eg. https://github.com/CesiumGS/cesium-webpack-example.