Add possibility to use es6 modules from data-story #1
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.
Prerequisites
Since data-story package is using es modules, we need to somehow reuse them in our node-js back-end application.
Using es modules
Start of a story
First of all we must include that lines in package.json to indicate that our code is using es modules
In our tsconfig we’re also specifying modules to be esnext
Problems with nest-js cli and fixes
With nest cli, tsc will compile the code, but another problem is that since our project now has module type, it requires all js code to have .mjs or .cjs extensions. Nest js and tsc just don’t handle it right now, when running our compiled code with node, it’ll throw an error. A lot of similar problems are being discussed on github
microsoft/TypeScript#18442
microsoft/TypeScript#35148
microsoft/TypeScript#37582
https://github.com/alshdavid/rxjs/blob/main/rollup.config.js#L10
To solve this kind of problem i decided to use rollup.js bundler. It can do what we want in 20 lines of code.
So now all code will be properly compiled to the dist folder.
Next step is replacing nest scripts with rollup and nodemon.
Excluding browser code from compiling
Nothing too clever here, just including what we want to see(types, utils, modules in core folder) and excluding what we don’t(browser related things)