Generate both CommonJS and ES modules #208
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #175
Based on this article: https://blog.logrocket.com/publishing-node-modules-typescript-es-modules/
I added a new tsconfig file to generate a new ESM bundle. I changed the output directory from
lib/src
tolib/{cjs,esm}/src
. I added a command tonpm run build
(that could have been parallelized with concurrently but maybe it's overkill).I tested
npm run build
and the ES modules worked withnpm link
from a local application that uses ES modules with Snowpack (and I confirm that the CommonJS build did not work because of some error with those generated lines:Object.defineProperty(exports, "__esModule", { value: true });
).Obviously I did not tested
npm publish
, so I hope I did not break the publication process.Note: I did not understand the need to include
tsconfig.package.json
in thelib/src
directory, so I kept it as-is in thelib/{cjs,esm}/src
directories.