Skip to content

Commit 5f5b5db

Browse files
author
David Heinemeier Hansson
committed
Join forces!
0 parents  commit 5f5b5db

22 files changed

+418
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.byebug_history
2+
*.gem

Gemfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
source 'https://rubygems.org'
2+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3+
4+
# Specify your gem's dependencies in importmap-rails.gemspec.
5+
gemspec
6+
7+
rails_version = ENV["RAILS_VERSION"] || "6.1.0"
8+
gem "rails", "~> #{rails_version}"
9+
10+
gem "sqlite3"
11+
12+
group :test do
13+
gem "turbo-rails"
14+
gem "stimulus-rails"
15+
16+
gem "byebug"
17+
18+
gem "rexml"
19+
gem "capybara"
20+
gem "selenium-webdriver"
21+
gem "webdrivers"
22+
end

Gemfile.lock

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
PATH
2+
remote: .
3+
specs:
4+
jsbundling-rails (0.1.0)
5+
rails (>= 6.0.0)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
actioncable (6.1.3.1)
11+
actionpack (= 6.1.3.1)
12+
activesupport (= 6.1.3.1)
13+
nio4r (~> 2.0)
14+
websocket-driver (>= 0.6.1)
15+
actionmailbox (6.1.3.1)
16+
actionpack (= 6.1.3.1)
17+
activejob (= 6.1.3.1)
18+
activerecord (= 6.1.3.1)
19+
activestorage (= 6.1.3.1)
20+
activesupport (= 6.1.3.1)
21+
mail (>= 2.7.1)
22+
actionmailer (6.1.3.1)
23+
actionpack (= 6.1.3.1)
24+
actionview (= 6.1.3.1)
25+
activejob (= 6.1.3.1)
26+
activesupport (= 6.1.3.1)
27+
mail (~> 2.5, >= 2.5.4)
28+
rails-dom-testing (~> 2.0)
29+
actionpack (6.1.3.1)
30+
actionview (= 6.1.3.1)
31+
activesupport (= 6.1.3.1)
32+
rack (~> 2.0, >= 2.0.9)
33+
rack-test (>= 0.6.3)
34+
rails-dom-testing (~> 2.0)
35+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
36+
actiontext (6.1.3.1)
37+
actionpack (= 6.1.3.1)
38+
activerecord (= 6.1.3.1)
39+
activestorage (= 6.1.3.1)
40+
activesupport (= 6.1.3.1)
41+
nokogiri (>= 1.8.5)
42+
actionview (6.1.3.1)
43+
activesupport (= 6.1.3.1)
44+
builder (~> 3.1)
45+
erubi (~> 1.4)
46+
rails-dom-testing (~> 2.0)
47+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
48+
activejob (6.1.3.1)
49+
activesupport (= 6.1.3.1)
50+
globalid (>= 0.3.6)
51+
activemodel (6.1.3.1)
52+
activesupport (= 6.1.3.1)
53+
activerecord (6.1.3.1)
54+
activemodel (= 6.1.3.1)
55+
activesupport (= 6.1.3.1)
56+
activestorage (6.1.3.1)
57+
actionpack (= 6.1.3.1)
58+
activejob (= 6.1.3.1)
59+
activerecord (= 6.1.3.1)
60+
activesupport (= 6.1.3.1)
61+
marcel (~> 1.0.0)
62+
mini_mime (~> 1.0.2)
63+
activesupport (6.1.3.1)
64+
concurrent-ruby (~> 1.0, >= 1.0.2)
65+
i18n (>= 1.6, < 2)
66+
minitest (>= 5.1)
67+
tzinfo (~> 2.0)
68+
zeitwerk (~> 2.3)
69+
addressable (2.8.0)
70+
public_suffix (>= 2.0.2, < 5.0)
71+
builder (3.2.4)
72+
byebug (11.1.3)
73+
capybara (3.35.3)
74+
addressable
75+
mini_mime (>= 0.1.3)
76+
nokogiri (~> 1.8)
77+
rack (>= 1.6.0)
78+
rack-test (>= 0.6.3)
79+
regexp_parser (>= 1.5, < 3.0)
80+
xpath (~> 3.2)
81+
childprocess (3.0.0)
82+
concurrent-ruby (1.1.9)
83+
crass (1.0.6)
84+
erubi (1.10.0)
85+
globalid (0.5.1)
86+
activesupport (>= 5.0)
87+
i18n (1.8.10)
88+
concurrent-ruby (~> 1.0)
89+
loofah (2.10.0)
90+
crass (~> 1.0.2)
91+
nokogiri (>= 1.5.9)
92+
mail (2.7.1)
93+
mini_mime (>= 0.1.1)
94+
marcel (1.0.1)
95+
method_source (1.0.0)
96+
mini_mime (1.0.3)
97+
minitest (5.14.4)
98+
nio4r (2.5.7)
99+
nokogiri (1.11.7-arm64-darwin)
100+
racc (~> 1.4)
101+
nokogiri (1.11.7-x86_64-darwin)
102+
racc (~> 1.4)
103+
nokogiri (1.11.7-x86_64-linux)
104+
racc (~> 1.4)
105+
public_suffix (4.0.6)
106+
racc (1.5.2)
107+
rack (2.2.3)
108+
rack-test (1.1.0)
109+
rack (>= 1.0, < 3)
110+
rails (6.1.3.1)
111+
actioncable (= 6.1.3.1)
112+
actionmailbox (= 6.1.3.1)
113+
actionmailer (= 6.1.3.1)
114+
actionpack (= 6.1.3.1)
115+
actiontext (= 6.1.3.1)
116+
actionview (= 6.1.3.1)
117+
activejob (= 6.1.3.1)
118+
activemodel (= 6.1.3.1)
119+
activerecord (= 6.1.3.1)
120+
activestorage (= 6.1.3.1)
121+
activesupport (= 6.1.3.1)
122+
bundler (>= 1.15.0)
123+
railties (= 6.1.3.1)
124+
sprockets-rails (>= 2.0.0)
125+
rails-dom-testing (2.0.3)
126+
activesupport (>= 4.2.0)
127+
nokogiri (>= 1.6)
128+
rails-html-sanitizer (1.3.0)
129+
loofah (~> 2.3)
130+
railties (6.1.3.1)
131+
actionpack (= 6.1.3.1)
132+
activesupport (= 6.1.3.1)
133+
method_source
134+
rake (>= 0.8.7)
135+
thor (~> 1.0)
136+
rake (13.0.6)
137+
regexp_parser (2.1.1)
138+
rexml (3.2.5)
139+
rubyzip (2.3.2)
140+
selenium-webdriver (3.142.7)
141+
childprocess (>= 0.5, < 4.0)
142+
rubyzip (>= 1.2.2)
143+
sprockets (4.0.2)
144+
concurrent-ruby (~> 1.0)
145+
rack (> 1, < 3)
146+
sprockets-rails (3.2.2)
147+
actionpack (>= 4.0)
148+
activesupport (>= 4.0)
149+
sprockets (>= 3.0.0)
150+
sqlite3 (1.4.2)
151+
stimulus-rails (0.3.8)
152+
rails (>= 6.0.0)
153+
thor (1.1.0)
154+
turbo-rails (0.7.4)
155+
rails (>= 6.0.0)
156+
tzinfo (2.0.4)
157+
concurrent-ruby (~> 1.0)
158+
webdrivers (4.6.0)
159+
nokogiri (~> 1.6)
160+
rubyzip (>= 1.3.0)
161+
selenium-webdriver (>= 3.0, < 4.0)
162+
websocket-driver (0.7.5)
163+
websocket-extensions (>= 0.1.0)
164+
websocket-extensions (0.1.5)
165+
xpath (3.2.0)
166+
nokogiri (~> 1.8)
167+
zeitwerk (2.4.2)
168+
169+
PLATFORMS
170+
arm64-darwin-20
171+
x86_64-darwin-20
172+
x86_64-linux
173+
174+
DEPENDENCIES
175+
byebug
176+
capybara
177+
rails (~> 6.1.0)
178+
rexml
179+
jsbundling-rails!
180+
selenium-webdriver
181+
sqlite3
182+
stimulus-rails
183+
turbo-rails
184+
webdrivers
185+
186+
BUNDLED WITH
187+
2.2.24

MIT-LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2021 David Heinemeier Hansson
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# JavaScript Bundling for Rails
2+
3+
Use [esbuild](https://esbuild.github.io), [rollup.js](https://rollupjs.org), or [Webpack](https://webpack.js.org) to bundle your JavaScript, then deliver it via the asset pipeline in Rails. This gem provides installers to get you going with the bundler of your choice in a new Rails application, and a convention to use `app/assets/bundles` to hold your bundled output as artifacts that are not checked into source control (the installer adds this directory to `.gitignore` by default).
4+
5+
You develop using this approach by running the bundler in watch mode in a terminal with `yarn build --watch` (and your Rails server in another, if you're not using something like [puma-dev](https://github.com/puma/puma-dev)). Whenever the bundler detects changes to any of the JavaScript files in your project, it'll bundle `app/javascript/application.js` into `app/assets/bundles/javascript.js` (and all other entry points placed in the root of `app/javascript`). You can refer to the build output in your layout using the standard asset pipeline approach with `<%= javascript_include_tag "application" %>`.
6+
7+
When you deploy your application to production, the bundler attaches to the `assets:precompile` task to ensure that all your package dependencies from `package.json` have been installed via npm, and then runs `yarn build` to process all the entry points, as it would in development. The latter files are then picked up by the asset pipeline, digested, and copied into public/assets, as any other asset pipeline file.
8+
9+
This also happens in testing where the bundler attaches to the `test:prepare` task to ensure the JavaScript has been bundled before testing commences. (Note that this currently only applies to rails `test:*` tasks (like `test:all` or `test:controllers`), not "rails test", as that doesn't load `test:prepare`).
10+
11+
That's it!
12+
13+
You can configure your bundler options in the `build` script in `package.json` or via the installer-generated rollup.config.js for rollup.js or webpack.config.json for Webpack (esbuild does not have a default configuration format).
14+
15+
16+
## Installation
17+
18+
You must already have node and yarn installed on your system. Then:
19+
20+
1. Add `jsbundling-rails` to your Gemfile with `gem 'jsbundling-rails'`
21+
2. Run `./bin/bundle install`
22+
3. Run `./bin/rails javascript:[rollup|esbuild|webpack]:install`
23+
24+
Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp -j [rollup|esbuild|webpack]`.
25+
26+
27+
## License
28+
29+
rollup.js for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).

bin/release

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
VERSION=$1
4+
5+
printf "module Jsbundling\n VERSION = \"$VERSION\"\nend\n" > ./lib/jsbundling/version.rb
6+
bundle
7+
git add Gemfile.lock lib/jsbundling/version.rb
8+
git commit -m "Bump version for $VERSION"
9+
git push
10+
git tag v$VERSION
11+
git push --tags
12+
gem build jsbundling-rails.gemspec
13+
gem push "jsbundling-rails-$VERSION.gem" --host https://rubygems.org
14+
rm "jsbundling-rails-$VERSION.gem"

jsbundling-rails.gemspec

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require_relative "lib/jsbundling/version"
2+
3+
Gem::Specification.new do |spec|
4+
spec.name = "jsbundling-rails"
5+
spec.version = Jsbundling::VERSION
6+
spec.authors = [ "David Heinemeier Hansson" ]
7+
spec.email = "[email protected]"
8+
spec.homepage = "https://github.com/rails/jsbundling-rails"
9+
spec.summary = "Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack."
10+
spec.license = "MIT"
11+
12+
spec.files = Dir["lib/**/*", "MIT-LICENSE", "README.md"]
13+
14+
spec.add_dependency "rails", ">= 6.0.0"
15+
end

lib/install/application.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Entry point for the build script in your package.json

lib/install/esbuild/install.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
say "Create default package.json and install esbuild"
2+
copy_file "#{__dir__}/package.json", "package.json"
3+
run "yarn add esbuild"

lib/install/esbuild/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "app",
3+
"private": "true",
4+
"scripts": {
5+
"build": "esbuild app/javascript/*.* --bundle --outdir=app/assets/builds"
6+
}
7+
}

0 commit comments

Comments
 (0)