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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68b88826751bb695c1ca6fc0ec1b516260bdcf9e9d2ffdb82d2aa9a6920c5de2
4
- data.tar.gz: 94e6540dfa0c07d54531616d1b957fa47e2b2d0572f4e877c2cdea8fb2faf86e
3
+ metadata.gz: bef9049287a92769cfe3fd83b58b7f3a4786c99cf5eb1e282afbc96585733b4a
4
+ data.tar.gz: 15c8ead90aa291b6d5bbf1a495f7f92f6dbf6173dfa8016d5a2a9229f18ed8e5
5
5
  SHA512:
6
- metadata.gz: aff716a47c4964fddbbef2082a72857e313de582280ff45ebdf10774d1a971a45d02615568a033b6b9f103c98c8fd8072ffeeb3fa01bd4f37e3d39eaa2356cd5
7
- data.tar.gz: b82f71efcba827218a5904874680c5f16cc93f11ce5c1756c5a3ede6e6f6974189791101a8480a61985465cb951e60700b9e6bc04b1359ca4f0dc8b7866c2b38
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 and 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/esbuilds` to hold your bundled output as artifacts that are not checked into source control (the installer adds this directory to `.gitignore` by default).
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 `npm run 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/esbuilds/javascript.js`. You can refer to the build output in your layout using the standard asset pipeline approach with `<%= javascript_include_tag "application" %>`.
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 `npm run build` to process `app/javascript/application.js` into `app/assets/esbuilds/javascript.js`. The latter file is then picked up by the asset pipeline, digested, and copied into public/assets, as any other asset pipeline file.
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
 
@@ -1,3 +1,3 @@
1
1
  module Esbuild
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -1,17 +1,16 @@
1
- say "Compile into app/assets/esbuilds"
2
- directory "#{__dir__}/esbuilds", "app/assets/esbuilds"
3
- append_to_file "app/assets/config/manifest.js", %(//= link_tree ../esbuilds .js\n)
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/esbuilds\n)
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, before: /\s*<\/head>/ do <<-HTML
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 "npm i esbuild"
27
+ run "yarn add esbuild"
@@ -2,7 +2,6 @@
2
2
  "name": "myapp",
3
3
  "private": "true",
4
4
  "scripts": {
5
- "build": "esbuild app/javascript/application.js --outfile=app/assets/esbuilds/application.js --bundle",
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 npm run build"
2
+ desc "Compile using esbuild with yarn build"
3
3
  task :compile do
4
- system "npm install && npm run build"
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.0
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-02 00:00:00.000000000 Z
11
+ date: 2021-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails