diff --git a/lib/install/esbuild/install.rb b/lib/install/esbuild/install.rb index ab91aa7..65bb9df 100644 --- a/lib/install/esbuild/install.rb +++ b/lib/install/esbuild/install.rb @@ -2,7 +2,7 @@ run "yarn add esbuild" say "Add build script" -build_script = "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=/assets" +build_script = "esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets" case `npx -v`.to_f when 7.1...8.0 diff --git a/lib/install/install.rb b/lib/install/install.rb index e4c0b6b..a8e7dfe 100644 --- a/lib/install/install.rb +++ b/lib/install/install.rb @@ -14,10 +14,10 @@ if (app_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist? say "Add JavaScript include tag in application layout" insert_into_file app_layout_path.to_s, - %(\n <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>), before: /\s*<\/head>/ + %(\n <%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>), before: /\s*<\/head>/ else say "Default application.html.erb is missing!", :red - say %( Add <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> within the tag in your custom layout.) + say %( Add <%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %> within the tag in your custom layout.) end unless (app_js_entrypoint_path = Rails.root.join("app/javascript/application.js")).exist? diff --git a/lib/install/rollup/rollup.config.js b/lib/install/rollup/rollup.config.js index 088fd37..efc952c 100644 --- a/lib/install/rollup/rollup.config.js +++ b/lib/install/rollup/rollup.config.js @@ -4,7 +4,7 @@ export default { input: "app/javascript/application.js", output: { file: "app/assets/builds/application.js", - format: "iife", + format: "esm", inlineDynamicImports: true, sourcemap: true }, diff --git a/lib/install/webpack/webpack.config.js b/lib/install/webpack/webpack.config.js index ba2f173..557a746 100644 --- a/lib/install/webpack/webpack.config.js +++ b/lib/install/webpack/webpack.config.js @@ -10,6 +10,7 @@ module.exports = { output: { filename: "[name].js", sourceMapFilename: "[file].map", + chunkFormat: "module", path: path.resolve(__dirname, "app/assets/builds"), }, plugins: [