esbuild-rails 0.1.0 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -3
- data/lib/esbuild/version.rb +1 -1
- data/lib/install/install.rb +8 -9
- data/lib/install/package.json +1 -2
- data/lib/tasks/esbuild/compile.rake +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bef9049287a92769cfe3fd83b58b7f3a4786c99cf5eb1e282afbc96585733b4a
|
4
|
+
data.tar.gz: 15c8ead90aa291b6d5bbf1a495f7f92f6dbf6173dfa8016d5a2a9229f18ed8e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14ecd25d2e85ab98eecb18ec7686e49e74e33444f30808a290bba7551ee5ef1bb1fb1d13848d1bb5baea992db2371a47e2205e61ce428aca562518f4541cbab7
|
7
|
+
data.tar.gz: 3b7d99522da45bd89a72b3d126c7c292cd74528b723c35dc56d1b03905d10f7fea291adcd297541f7997bbc3168b013a19d0db03264a581bec3cdf5b9eb52814
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# esbuild for Rails
|
2
2
|
|
3
|
-
Use [esbuild](https://esbuild.github.io) to bundle your JavaScript
|
3
|
+
Use [esbuild](https://esbuild.github.io) to bundle your JavaScript, then deliver it via the asset pipeline in Rails. This gem provides an installer to get you going with esbuild in a new Rails application, and a convention to use `app/assets/builds` to hold your bundled output as artifacts that are not checked into source control (the installer adds this directory to `.gitignore` by default).
|
4
4
|
|
5
|
-
You develop using this approach by running esbuild in watch mode in a terminal with `
|
5
|
+
You develop using this approach by running esbuild 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 esbuild detects changes to any of the JavaScript files in your project, it'll bundle `app/javascript/application.js` into `app/assets/builds/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
6
|
|
7
|
-
When you deploy your application to production, esbuild attaches to the `assets:precompile` task to ensure that all your package dependencies from `package.json` have been installed via npm, and then runs `
|
7
|
+
When you deploy your application to production, esbuild 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 esbuild attaches to the `test:prepare` task to ensure the JavaScript has been compiled 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`).
|
8
10
|
|
9
11
|
That's it!
|
10
12
|
|
@@ -13,10 +15,19 @@ You can tailor the configuration of esbuild through the build script in `package
|
|
13
15
|
|
14
16
|
## Installation
|
15
17
|
|
18
|
+
You must already have node and yarn installed on your system. Then:
|
19
|
+
|
16
20
|
1. Add `esbuild-rails` to your Gemfile with `gem 'esbuild-rails'`
|
17
21
|
2. Run `./bin/bundle install`
|
18
22
|
3. Run `./bin/rails esbuild:install`
|
19
23
|
|
24
|
+
Or, in Rails 7+, you can preconfigure your new application to use esbuild with `rails new myapp -j esbuild`.
|
25
|
+
|
26
|
+
|
27
|
+
## The sister gem to rollupjs-rails
|
28
|
+
|
29
|
+
This gem is almost identical in setup and purpose to [`rollupjs-rails`](https://github.com/rails/rollupjs-rails), which follows the same conventions, but uses [rollup.js](https://rollupjs.org) instead.
|
30
|
+
|
20
31
|
|
21
32
|
## License
|
22
33
|
|
data/lib/esbuild/version.rb
CHANGED
data/lib/install/install.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
say "Compile into app/assets/
|
2
|
-
|
3
|
-
|
1
|
+
say "Compile into app/assets/builds"
|
2
|
+
empty_directory "app/assets/builds"
|
3
|
+
keep_file "app/assets/builds"
|
4
|
+
append_to_file "app/assets/config/manifest.js", %(//= link_tree ../builds .js\n)
|
4
5
|
|
5
6
|
if Rails.root.join(".gitignore").exist?
|
6
|
-
append_to_file ".gitignore", %(\n/app/assets/
|
7
|
+
append_to_file ".gitignore", %(\n/app/assets/builds\n)
|
7
8
|
end
|
8
9
|
|
9
10
|
if (app_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist?
|
10
11
|
say "Add esbuild include tag in application layout"
|
11
|
-
insert_into_file app_layout_path.to_s,
|
12
|
-
\n <%= javascript_include_tag "application", "data-track-turbo": "true", defer: true %>
|
13
|
-
HTML
|
14
|
-
end
|
12
|
+
insert_into_file app_layout_path.to_s,
|
13
|
+
%(\n <%= javascript_include_tag "application", "data-track-turbo": "true", defer: true %>), before: /\s*<\/head>/
|
15
14
|
else
|
16
15
|
say "Default application.html.erb is missing!", :red
|
17
16
|
say %( Add <%= javascript_include_tag "application", "data-track-turbo": "true", defer: true %> within the <head> tag in your custom layout.)
|
@@ -25,4 +24,4 @@ end
|
|
25
24
|
|
26
25
|
say "Create default package.json and install esbuild"
|
27
26
|
copy_file "#{__dir__}/package.json", "package.json"
|
28
|
-
run "
|
27
|
+
run "yarn add esbuild"
|
data/lib/install/package.json
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
"name": "myapp",
|
3
3
|
"private": "true",
|
4
4
|
"scripts": {
|
5
|
-
"build": "esbuild app/javascript
|
6
|
-
"watch": "npm run build -- --watch"
|
5
|
+
"build": "esbuild app/javascript/*.* --bundle --outdir=app/assets/builds"
|
7
6
|
}
|
8
7
|
}
|
@@ -1,8 +1,9 @@
|
|
1
1
|
namespace :esbuild do
|
2
|
-
desc "Compile using esbuild with
|
2
|
+
desc "Compile using esbuild with yarn build"
|
3
3
|
task :compile do
|
4
|
-
system "
|
4
|
+
system "yarn install && yarn build"
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
8
|
Rake::Task["assets:precompile"].enhance(["esbuild:compile"])
|
9
|
+
Rake::Task["test:prepare"].enhance(["esbuild:compile"])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esbuild-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|