The default javascript_include_tag added to application.html.erbhas type='text/javascript', which can cause problems when the bundler output is in ESM format. If the bundler outputs ESM code, we need to import it with type="module". Otherwise the module varibles end up in the global scope. See https://github.com/hotwired/turbo/pull/1077
The default
javascript_include_tag
added toapplication.html.erb
hastype='text/javascript'
, which can cause problems when the bundler output is in ESM format. If the bundler outputs ESM code, we need to import it withtype="module"
. Otherwise the module varibles end up in the global scope. See https://github.com/hotwired/turbo/pull/1077This is especially problematic for bun.js, because bun can only emit
ESM
code at the moment.This PR updates the install generator to add the
type="module"
attribute to the defaultjavascript_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 output ESM bundles.
--format=esm
flag https://esbuild.github.io/api/#format-esmoutput.chunkFormat
https://webpack.js.org/configuration/output/#outputchunkformatoutput.format
https://rollupjs.org/configuration-options/#output-format