esbuild-rails 0.1.0
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +23 -0
- data/lib/esbuild/engine.rb +4 -0
- data/lib/esbuild/version.rb +3 -0
- data/lib/esbuild-rails.rb +5 -0
- data/lib/install/application.js +1 -0
- data/lib/install/install.rb +28 -0
- data/lib/install/package.json +8 -0
- data/lib/tasks/esbuild/compile.rake +8 -0
- data/lib/tasks/esbuild/install.rake +6 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 68b88826751bb695c1ca6fc0ec1b516260bdcf9e9d2ffdb82d2aa9a6920c5de2
|
4
|
+
data.tar.gz: 94e6540dfa0c07d54531616d1b957fa47e2b2d0572f4e877c2cdea8fb2faf86e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aff716a47c4964fddbbef2082a72857e313de582280ff45ebdf10774d1a971a45d02615568a033b6b9f103c98c8fd8072ffeeb3fa01bd4f37e3d39eaa2356cd5
|
7
|
+
data.tar.gz: b82f71efcba827218a5904874680c5f16cc93f11ce5c1756c5a3ede6e6f6974189791101a8480a61985465cb951e60700b9e6bc04b1359ca4f0dc8b7866c2b38
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2021 Basecamp
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# esbuild for Rails
|
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).
|
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" %>`.
|
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.
|
8
|
+
|
9
|
+
That's it!
|
10
|
+
|
11
|
+
You can tailor the configuration of esbuild through the build script in `package.json`. Or if you want to get fancy with plugins, you can setup an [external configuration](https://esbuild.github.io/getting-started/#build-scripts) to run through node.
|
12
|
+
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
1. Add `esbuild-rails` to your Gemfile with `gem 'esbuild-rails'`
|
17
|
+
2. Run `./bin/bundle install`
|
18
|
+
3. Run `./bin/rails esbuild:install`
|
19
|
+
|
20
|
+
|
21
|
+
## License
|
22
|
+
|
23
|
+
esbuild for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1 @@
|
|
1
|
+
// Entrypoint for the esbuild command defined in package.json scripts
|
@@ -0,0 +1,28 @@
|
|
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)
|
4
|
+
|
5
|
+
if Rails.root.join(".gitignore").exist?
|
6
|
+
append_to_file ".gitignore", %(\n/app/assets/esbuilds\n)
|
7
|
+
end
|
8
|
+
|
9
|
+
if (app_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist?
|
10
|
+
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
|
15
|
+
else
|
16
|
+
say "Default application.html.erb is missing!", :red
|
17
|
+
say %( Add <%= javascript_include_tag "application", "data-track-turbo": "true", defer: true %> within the <head> tag in your custom layout.)
|
18
|
+
end
|
19
|
+
|
20
|
+
unless (app_js_entrypoint_path = Rails.root.join("app/javascript/application.js")).exist?
|
21
|
+
say "Create default entrypoint in app/javascript/application.js"
|
22
|
+
empty_directory app_js_entrypoint_path.parent.to_s
|
23
|
+
copy_file "#{__dir__}/application.js", app_js_entrypoint_path
|
24
|
+
end
|
25
|
+
|
26
|
+
say "Create default package.json and install esbuild"
|
27
|
+
copy_file "#{__dir__}/package.json", "package.json"
|
28
|
+
run "npm i esbuild"
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: esbuild-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Heinemeier Hansson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.0.0
|
27
|
+
description:
|
28
|
+
email: david@loudthinking.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- MIT-LICENSE
|
34
|
+
- README.md
|
35
|
+
- lib/esbuild-rails.rb
|
36
|
+
- lib/esbuild/engine.rb
|
37
|
+
- lib/esbuild/version.rb
|
38
|
+
- lib/install/application.js
|
39
|
+
- lib/install/install.rb
|
40
|
+
- lib/install/package.json
|
41
|
+
- lib/tasks/esbuild/compile.rake
|
42
|
+
- lib/tasks/esbuild/install.rake
|
43
|
+
homepage: https://github.com/rails/esbuild-rails
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.1.4
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Bundle and transpile JavaScript in Rails with esbuild.
|
66
|
+
test_files: []
|