Commit 880a1bd
authored
Import application JS as a module (#178)
Bun.js generates JS bundles in the ESM format and they need be imported with
the `type="module"` attribute. Otherwise the module varibles end up in the
global scope. See hotwired/turbo#1077
This commit updates the install generator to add the type="module" attribute
to the default `javascript_include_tag`.
`defer` is no longer needed, as JS modules are deferred by default.
Ref. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#other_differences_between_modules_and_standard_scripts
This PR also updates the default config to ensure that all bundlers are
configured to output ESM bundles.
- bun only supports ESM at the moment https://bun.sh/docs/bundler#format
- esbuild is configured to output ESM with the --format=esm flag https://esbuild.github.io/api/#format-esm
- webpacker is configured to output ESM bundles with `output.chunkFormat` https://webpack.js.org/configuration/output/#outputchunkformat
- rollup is configured to output ESM bundles with `output.format` https://rollupjs.org/configuration-options/#output-format1 parent 95a5472 commit 880a1bd
File tree
4 files changed
+5
-4
lines changed- lib/install
- esbuild
- rollup
- webpack
4 files changed
+5
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
0 commit comments