Skip to content

Commit

Permalink
Install webpacker
Browse files Browse the repository at this point in the history
  • Loading branch information
aktfrikshun authored Apr 20, 2022
1 parent f1f3f07 commit ff65e3c
Show file tree
Hide file tree
Showing 18 changed files with 495 additions and 903 deletions.
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
defaults
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
- v1-bundle-{{ checksum "Gemfile.lock" }}

- run: bundle install
- run: yarn install
- run: yarn add @hotwired/stimulus
- run: bundle exec rails webpacker:install
- run: bundle exec rails webpacker:compile

- save_cache:
paths:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ gem 'sass-rails', '>= 6.0.0'
gem 'sidekiq'
gem 'json-jwt'
gem 'aasm', '~> 5.2.0'
gem 'webpacker', '~> 6.0.0.rc.6'
gem 'webpacker'
gem 'whenever', require: false
gem 'logstop'
gem 'paper_trail'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ GEM
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0)
webpacker (6.0.0.rc.6)
webpacker (5.4.3)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
Expand Down Expand Up @@ -548,7 +548,7 @@ DEPENDENCIES
tzinfo-data
web-console (>= 4.2.0)
webdrivers (>= 5.0.0)
webpacker (~> 6.0.0.rc.6)
webpacker
whenever

RUBY VERSION
Expand Down
1 change: 0 additions & 1 deletion app/controllers/site_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ def status
end

def hello_stimulus
render :layout => "stimulus_application"
end
end
1 change: 1 addition & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./controllers"
9 changes: 9 additions & 0 deletions app/javascript/controllers/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Application } from "@hotwired/stimulus"

const application = Application.start()

// Configure Stimulus development experience
application.debug = false
window.Stimulus = application

export { application }
7 changes: 3 additions & 4 deletions app/javascript/controllers/hello_controller.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// src/controllers/hello_controller.js
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
greet() {
console.log("Hello, Stimulus!", this.element)
connect() {
this.element.textContent = "Hello from Stimulus!"
}
}
}
13 changes: 6 additions & 7 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Load all the controllers within this directory and all subdirectories.
// Controller files must be named *_controller.js.
// This file is auto-generated by ./bin/rails stimulus:manifest:update
// Run that command whenever you add a new controller or create them with
// ./bin/rails generate stimulus controllerName

import { Application } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"
import { application } from "./application"

const application = Application.start()
const context = require.context("controllers", true, /_controller\.js$/)
application.load(definitionsFromContext(context))
import HelloController from "./hello_controller"
application.register("hello", HelloController)
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<%= stylesheet_link_tag 'application', media: 'all', integrity: true %>
<%= javascript_include_tag 'application', integrity: true %>
<%= render 'components/analytics/script_header' %>
<%= javascript_pack_tag "application", integrity: true %>
</head>
<body>
<%= render 'components/analytics/script_body' %>
Expand Down
39 changes: 0 additions & 39 deletions app/views/layouts/stimulus_application.html.erb

This file was deleted.

3 changes: 3 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ FileUtils.chdir APP_ROOT do
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")

# Install JavaScript dependencies
system! "bin/yarn"

# puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml")
# FileUtils.cp "config/database.yml.sample", "config/database.yml"
Expand Down
5 changes: 3 additions & 2 deletions bin/yarn
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)

APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
yarn = ENV["PATH"].split(File::PATH_SEPARATOR).
select { |dir| File.expand_path(dir) != __dir__ }.
product(["yarn", "yarn.cmd", "yarn.ps1"]).
product(["yarn", "yarnpkg", "yarn.cmd", "yarn.ps1"]).
map { |dir, file| File.expand_path(file, dir) }.
find { |file| File.executable?(file) }

Expand Down
3 changes: 3 additions & 0 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

# Add node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join("node_modules")
4 changes: 3 additions & 1 deletion config/initializers/content_security_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# For further information see the following documentation
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy

# Rails.application.config.content_security_policy do |policy|
# Rails.application.config.content_security_policy do |policy| # # If you are using webpack-dev-server then specify webpack-dev-server host
# policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?

# policy.default_src :self, :https
# policy.font_src :self, :https, :data
# policy.img_src :self, :https, :data
Expand Down
3 changes: 3 additions & 0 deletions config/webpack/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { webpackConfig } = require('@rails/webpacker')

module.exports = webpackConfig
17 changes: 0 additions & 17 deletions package.json

This file was deleted.

Loading

0 comments on commit ff65e3c

Please sign in to comment.