Skip to content
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

This should probably work in an ES5 app #11

Closed
tomwayson opened this issue Mar 15, 2017 · 2 comments · Fixed by #17
Closed

This should probably work in an ES5 app #11

tomwayson opened this issue Mar 15, 2017 · 2 comments · Fixed by #17

Comments

@tomwayson
Copy link
Member

tomwayson commented Mar 15, 2017

B/c this outputs to CJS there are exports statements in the built code (https://unpkg.com/esri-loader@0.1.3/index.js) this won't work in ES5. I tried pulling the build output into Ember via bower and it chokes on the exports.

Seems like CJS was needed for Angular dc92251. It may be that the tsc UMD build output was problematic for Angular (now starting to see why other libs use webpack instead of tsc to do builds).

Would love to know that the right pattern is here.

@tomwayson
Copy link
Member Author

tomwayson commented Apr 7, 2017

Ultimately, I'd like to try to follow the main and module pattern described here.

Emulating the Angular pattern described in that post or emulating moment might look like:

{
  "name": "esri-loader",
  "main": "./dist/esri-loader.umd.js",
  "module": "./esri-loader.js",
  ···
}

Where main is a UMD module and module

But, there are a few problems w/ this. First, we should rename the the source to "esri-loader.ts" (I regret using "index.ts" - the only reason I did was b/c I thought TS consumers would be able to load the TS code directly). However, other libs like angular2-esri-loader have caused their own dependencies to depend on this library. In theory as long as the module loaders (like webpack) used in those apps respect the above package.json fields, we should be able to move the files around, but I had a nightmare figuring out how to get it successfully published in the first place, I'm really hesitant to remove the one thing I know works (./index.js as a CJS module).

Also, it looks like tsc is not really capable of outputting either of those:

Only "AMD" and "System" can be used in conjunction with --outFile.
"ES6" and "ES2015" values may not be used when targeting "ES5" or lower.

I really can't understand why everyone loves TypeScript.

That seems like more likely reason that I was seeing Angular libraries use webpack to do their builds.

Looks like I'm going to have to add a real build pipeline here.

@tomwayson
Copy link
Member Author

OK, I take back half of what I said about TS - it may be the source of the problem (in that the UMD build was not consumable), but at least it seems to be part of the solution.

Despite what the above docs say, you can use "target": "es5" with "module": "es2015", so that allowed me to create the build for pkg.module. I then added Rollup to do a UMD build that I know will work.

🤞 that this will actually work in all environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant