exports
field implies ES2019 code because it is only available in Node 12.8. (main
can still be used as an ES5 fallback)type="module"
and type="nomodule"
attributes added to your <script>
tagsThere are two ways of supporting both modern and older browsers:
Generating bundles for different targets is usually simple with bundlers. For example, rollup supports bundling from several unrelated inputs to several outputs.
1// rollup.config.js (building more than one bundle)
2
3export default [
4 {
5 input: 'main-a.js',
6 output: {
7 file: 'dist/bundle-a.js',
8 format: 'cjs',
9 },
10 },
11 {
12 input: 'main-b.js',
13 output: [
14 {
15 file: 'dist/bundle-b1.js',
16 format: 'cjs',
17 },
18 {
19 file: 'dist/bundle-b2.js',
20 format: 'es',
21 },
22 ],
23 },
24]
1tsc -p /path/to/first/tsconfig.json --outFile controllers.js
2tsc -p /path/to/second/tsconfig.json --outFile plugins.js
or if outFile
or outDir
is mentioned inside the tsconfig.json
1tsc -p /path/to/first/tsconfig.json
2tsc -p /path/to/second/tsconfig.json
Use tsc
to transpile the Typescript into an intermediate build folder, then I use rollup to bundle that transpiled code and output it to the desired destination.