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

Generate a package using Rollup #2

Merged
merged 3 commits into from
Jan 3, 2021
Merged

Generate a package using Rollup #2

merged 3 commits into from
Jan 3, 2021

Conversation

robertknight
Copy link
Owner

Compile all the modules into a single package in the dist/ directory using Rollup.

To do this with minimal adding tooling required changing TypeScript compilation to output native ES modules into the build/ directory. This in turn required changing the whole package to a native ES module package by editing the type field in package.json and rewriting import specifiers to include a file extension.

Somewhat confusingly, the extension in the .ts source files needs to end in .js. See microsoft/TypeScript#42151 (comment).

Add `yarn package` command that builds a package. Making the output of
TypeScript compilation work as rollup input required changing the TS
module output type to native ES modules. This currently breaks test
execution. That will be fixed in the next commit.
Use native ES modules everywhere for consistency between source and
tests and to allow the output of TypeScript compilation to function both
as input to Rollup packaging and execution by mocha.

Node ES module support requires that file extensions are always
explicitly specified. TypeScript does not generate the ".js" extension
itself but counter-intuitively does allow it to be specified in the
original source [1].

[1] microsoft/TypeScript#42151 (comment)
Setting the package's `type` field affects how it is loaded both in
development and also when importing it directly using Node.

Let's try making it an ES module when published as well.
@robertknight robertknight merged commit d2cd558 into main Jan 3, 2021
@robertknight robertknight deleted the rollup-package branch January 3, 2021 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant