jsbundling-rails 1.0.3 → 1.1.2
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 -9
- data/lib/install/Procfile.dev +1 -1
- data/lib/install/dev +3 -4
- data/lib/install/esbuild/install.rb +8 -4
- data/lib/install/rollup/install.rb +8 -4
- data/lib/install/rollup/rollup.config.js +1 -1
- data/lib/install/webpack/install.rb +7 -3
- data/lib/jsbundling/version.rb +1 -1
- data/lib/tasks/jsbundling/build.rake +13 -3
- data/lib/tasks/jsbundling/clobber.rake +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e87af17983ef465c2f92f63a3943df1ed2f1508eec23644f4134bdef5430ec27
|
4
|
+
data.tar.gz: de600a6cefeb7f190d1348f7edbe328d71fe13aeff2dd8903dcc4ff78a029a60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06f0040b3476411f6bcb1bfcef1280763161c53a2dddb9087c180f31e8b360992dcb6191aa04c08755298d69b3f5671a5583a435b1a988b55fca2370a794958f
|
7
|
+
data.tar.gz: 18f37485ec256760ed0343d820da6798b6e2f358d4db3c9a653f4d95ccc961c11db4380c25add8d2e6776bcbc058e56229563c7d4fb261b53efc9f9f795335fb
|
data/README.md
CHANGED
@@ -8,9 +8,7 @@ Whenever the bundler detects changes to any of the JavaScript files in your proj
|
|
8
8
|
|
9
9
|
When you deploy your application to production, the `javascript:build` task attaches to the `assets:precompile` task to ensure that all your package dependencies from `package.json` have been installed via yarn, 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.
|
10
10
|
|
11
|
-
This also happens in testing where the bundler attaches to the `test:prepare` task to ensure the JavaScript has been bundled before testing commences.
|
12
|
-
|
13
|
-
If your testing library of choice does not define a `test:prepare` Rake task, ensure that your test suite runs `javascript:build` to bundle JavaScript before testing commences.
|
11
|
+
This also happens in testing where the bundler attaches to the `test:prepare` task to ensure the JavaScript has been bundled before testing commences. If your testing library of choice does not call the `test:prepare` Rake task, ensure that your test suite runs `javascript:build` to bundle JavaScript before testing commences.
|
14
12
|
|
15
13
|
That's it!
|
16
14
|
|
@@ -22,10 +20,15 @@ If you want to use webpack features like [code splitting](https://webpack.js.org
|
|
22
20
|
|
23
21
|
## Installation
|
24
22
|
|
25
|
-
You must already have node and yarn installed on your system. You will also need npx version 7.1.0 or later. Then:
|
23
|
+
You must already have node and yarn installed on your system. You will also need npx version 7.1.0 or later. Then run:
|
24
|
+
|
25
|
+
```
|
26
|
+
./bin/bundle add jsbundling-rails
|
27
|
+
```
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
+
```
|
30
|
+
./bin/rails javascript:install:[esbuild|rollup|webpack]
|
31
|
+
```
|
29
32
|
|
30
33
|
Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp -j [esbuild|rollup|webpack]`.
|
31
34
|
|
@@ -45,11 +48,13 @@ If you [import CSS](https://esbuild.github.io/content-types/#css-from-js) in you
|
|
45
48
|
Suppose you have an image `app/javascript/images/example.png` that you need to reference in frontend code built with esbuild.
|
46
49
|
|
47
50
|
1. Create the image at `app/javascript/images/example.png`.
|
48
|
-
1. In `package.json`, under `"scripts"` and `"build"`, add the
|
49
|
-
|
51
|
+
1. In `package.json`, under `"scripts"` and `"build"`, add the additional arguments:
|
52
|
+
* `--loader:.png=file` This instructs esbuild to copy png files to the build directory.
|
53
|
+
* `--asset-names=[name]-[hash].digested` This tells esbuild to append `.digested` to the file name so that sprockets or propshaft will not append an additional digest hash to the file.
|
54
|
+
1. When esbuild runs, it will copy the png file to something like `app/assets/builds/example-5SRKKTLZ.digested.png`.
|
50
55
|
1. In frontend code, the image is available for import by its original name: `import Example from "../images/example.png"`.
|
51
56
|
1. The image itself can now be referenced by its imported name, e.g. in React, `<img src={Example} />`.
|
52
|
-
1. The path of the image resolves to `/assets/example-5SRKKTLZ.png`, which is served by the asset pipeline.
|
57
|
+
1. The path of the image resolves to `/assets/example-5SRKKTLZ.digested.png`, which is served by the asset pipeline.
|
53
58
|
|
54
59
|
## License
|
55
60
|
|
data/lib/install/Procfile.dev
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
web: bin/rails server
|
1
|
+
web: unset PORT && env RUBY_DEBUG_OPEN=true bin/rails server
|
2
2
|
js: yarn build --watch
|
data/lib/install/dev
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
#!/usr/bin/env
|
1
|
+
#!/usr/bin/env sh
|
2
2
|
|
3
|
-
if ! foreman
|
4
|
-
then
|
3
|
+
if ! gem list foreman -i --silent; then
|
5
4
|
echo "Installing foreman..."
|
6
5
|
gem install foreman
|
7
6
|
fi
|
8
7
|
|
9
|
-
foreman start -f Procfile.dev "$@"
|
8
|
+
exec foreman start -f Procfile.dev "$@"
|
@@ -2,11 +2,15 @@ say "Install esbuild"
|
|
2
2
|
run "yarn add esbuild"
|
3
3
|
|
4
4
|
say "Add build script"
|
5
|
-
build_script = "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path
|
5
|
+
build_script = "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=/assets"
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
else
|
7
|
+
case `npx -v`.to_f
|
8
|
+
when 7.1...8.0
|
10
9
|
run %(npm set-script build "#{build_script}")
|
11
10
|
run %(yarn build)
|
11
|
+
when (8.0..)
|
12
|
+
run %(npm pkg set scripts.build="#{build_script}")
|
13
|
+
run %(yarn build)
|
14
|
+
else
|
15
|
+
say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
|
12
16
|
end
|
@@ -3,11 +3,15 @@ copy_file "#{__dir__}/rollup.config.js", "rollup.config.js"
|
|
3
3
|
run "yarn add rollup @rollup/plugin-node-resolve"
|
4
4
|
|
5
5
|
say "Add build script"
|
6
|
-
build_script = "rollup -c rollup.config.js"
|
6
|
+
build_script = "rollup -c --bundleConfigAsCjs rollup.config.js"
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
else
|
8
|
+
case `npx -v`.to_f
|
9
|
+
when 7.1...8.0
|
11
10
|
run %(npm set-script build "#{build_script}")
|
12
11
|
run %(yarn build)
|
12
|
+
when (8.0..)
|
13
|
+
run %(npm pkg set scripts.build="#{build_script}")
|
14
|
+
run %(yarn build)
|
15
|
+
else
|
16
|
+
say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
|
13
17
|
end
|
@@ -5,9 +5,13 @@ run "yarn add webpack webpack-cli"
|
|
5
5
|
say "Add build script"
|
6
6
|
build_script = "webpack --config webpack.config.js"
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
else
|
8
|
+
case `npx -v`.to_f
|
9
|
+
when 7.1...8.0
|
11
10
|
run %(npm set-script build "#{build_script}")
|
12
11
|
run %(yarn build)
|
12
|
+
when (8.0..)
|
13
|
+
run %(npm pkg set scripts.build="#{build_script}")
|
14
|
+
run %(yarn build)
|
15
|
+
else
|
16
|
+
say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
|
13
17
|
end
|
data/lib/jsbundling/version.rb
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
namespace :javascript do
|
2
|
+
desc "Install JavaScript dependencies"
|
3
|
+
task :install do
|
4
|
+
unless system "yarn install"
|
5
|
+
raise "jsbundling-rails: Command install failed, ensure yarn is installed"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
2
9
|
desc "Build your JavaScript bundle"
|
3
|
-
task :build do
|
4
|
-
unless system "yarn
|
5
|
-
raise "jsbundling-rails: Command build failed, ensure
|
10
|
+
build_task = task :build do
|
11
|
+
unless system "yarn build"
|
12
|
+
raise "jsbundling-rails: Command build failed, ensure `yarn build` runs without errors"
|
6
13
|
end
|
7
14
|
end
|
15
|
+
build_task.prereqs << :install unless ENV["SKIP_YARN_INSTALL"]
|
8
16
|
end
|
9
17
|
|
10
18
|
if Rake::Task.task_defined?("assets:precompile")
|
@@ -13,6 +21,8 @@ end
|
|
13
21
|
|
14
22
|
if Rake::Task.task_defined?("test:prepare")
|
15
23
|
Rake::Task["test:prepare"].enhance(["javascript:build"])
|
24
|
+
elsif Rake::Task.task_defined?("spec:prepare")
|
25
|
+
Rake::Task["spec:prepare"].enhance(["javascript:build"])
|
16
26
|
elsif Rake::Task.task_defined?("db:test:prepare")
|
17
27
|
Rake::Task["db:test:prepare"].enhance(["javascript:build"])
|
18
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsbundling-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.2
|
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:
|
11
|
+
date: 2023-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
requirements: []
|
70
|
-
rubygems_version: 3.
|
70
|
+
rubygems_version: 3.4.10
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack.
|