Appearance
esm and cjs co-existence
- so like electron needs it's stuff in commonjs
- most of my electron apps already use utils.js as a commonjs module
- svelte needs it's stuff in esm
- the way i've solved it i put general (not requiring node modules) utils in a separate esm module (in subfolder) like this:
- the subfolder's
package.json
has this:{"type": "module"}
so its an esm module - all functions in (esm) lib.js are exported like this:
export function shortenFilename(){...}
- the
utils.js
imports all the lib's functions with standard named imports and require, and exports them usingmodule.exports = { namedExports }
- the main
package.json
has this added for it to work:json{ ... "exports": { "require": "./utils.js", "import": "./esm/lib.js" } }
to see the whole lib and more detaills, check this: https://github.com/KraXen72/roseboxlib