Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compile to ES2015 modules instead of commonjs
Caveat: I have not tested whether this package will build correctly or not. I was only able to test it locally using `npm run build` and then using `npm link ../$THIS_REPOSITORY` bundling it into a vanilla-ts Vite test page. Using ES modules (ESM) increases compatibility with modern tooling. Using commonjs regularly introduced issues when working various tools. One of those issues was directly using this package with unpkg.com or the `npm link` command, e.g. `npm link ../$THIS_REPO`, resulting in build errors complaining about a default export missing (presumably since ES modules are expected). Not being able to load this package using unpkg.com reduces testability, e.g., when wanting to try Sarus in a jsfiddle. Furthermore: It would be good to investigate at this point whether checking the dist/ folder into the repository makes sense at all. When building an NPM package, the dist folder can be packaged then, and since it can be derived using `npm run build` any time, it should be left out of the repository. Being able to load this package using unpkg.com makes it easier for developers to evaluate whether this package is usable for their needs. Previously one needed to install it with NPM and use a build system that explicitly supports common js modules. Every modern supported version of Node.js (the introducer of commonjs) supports ES modules as well. (See https://nodejs.org/api/esm.html) Bundlers that support ESM: - Webpack: https://webpack.js.org/guides/ecma-script-modules/ - Rollup (used by Vite): https://rollupjs.org/es-module-syntax/ Further note: Consider switching back to >= ES2015 build target. - https://caniuse.com/websockets: 97.17% - https://caniuse.com/es6: 97.15 Unless there is an argument to keep ES5, such as a specific client's use case, it would be good to update. Furthermore, core-js has polyfills for all es6 features: https://github.com/zloirock/core-js#ecmascript
- Loading branch information