Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
added imports
Browse files Browse the repository at this point in the history
  • Loading branch information
williamkennedy committed Oct 15, 2021
1 parent 8824f1d commit 1bf7b4c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
18 changes: 18 additions & 0 deletions esbuild.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require('path')
const rails = require('esbuild-rails')

const watch = process.argv.includes("--watch") && {
onRebuild(error) {
if (error) console.error("[watch] build failed", error);
else console.log("[watch] build finished");
},
};

require("esbuild").build({
entryPoints: ["application.js"],
bundle: true,
outdir: path.join(process.cwd(), "app/assets/builds"),
absWorkingDir: path.join(process.cwd(), "app/javascript"),
watch: watch,
plugins: [rails()],
}).catch(() => process.exit(1));
25 changes: 22 additions & 3 deletions template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ def add_jsbundling
end

def add_javascript
run "yarn add expose-loader @popperjs/core bootstrap local-time @rails/request.js"
run "yarn add expose-loader @popperjs/core bootstrap local-time @rails/request.js esbuild-rails"

if rails_5?
run "yarn add @rails/actioncable@pre @rails/actiontext@pre @rails/activestorage@pre @rails/ujs@pre"
run "yarn add @rails/actioncable@pre @rails/actiontext@pre @rails/activestorage@pre @rails/ujs@pre esbuild-rails"
end
end

Expand All @@ -159,6 +159,7 @@ def copy_templates
copy_file "Procfile"
copy_file "Procfile.dev"
copy_file ".foreman"
copy_file "esbuild.config.js"

directory "app", force: true
directory "config", force: true
Expand Down Expand Up @@ -242,6 +243,22 @@ def add_announcements_css
insert_into_file 'app/assets/stylesheets/application.bootstrap.scss', '@import "jumpstart/announcements";'
end

def add_esbuild_script
build_script = "esbuild app/javascript/*.* --bundle --outdir=app/assets/builds"
gsub_file "package.json", /#{build_script}/, "node esbuild.config.js"
end

def add_esbuild_imports
inject_into_file 'app/javascript/controllers/index.js' do <<~JS
import './channels/**/*_channel.js'
import controllers from './**/*_controller.js'
controllers.forEach((controller) => {
application.register(controller.name, controller.module.default)
})
JS
end
end

# Main setup
add_template_repository_to_source_path

Expand All @@ -266,6 +283,8 @@ def add_announcements_css
add_sitemap
add_bootstrap
add_announcements_css
add_esbuild_script
add_esbuild_imports

rails_command "active_storage:install"

Expand All @@ -292,5 +311,5 @@ def add_announcements_css
say " rails db:create db:migrate"
say " rails g madmin:install # Generate admin dashboards"
say " gem install foreman"
say " foreman start # Run Rails, sidekiq, and dev-server"
say " bin/dev"
end

0 comments on commit 1bf7b4c

Please sign in to comment.