jsbundling-rails 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -4
- 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/webpack/install.rb +7 -3
- data/lib/install/webpack/webpack.config.js +1 -1
- data/lib/jsbundling/version.rb +1 -1
- data/lib/tasks/jsbundling/build.rake +2 -0
- 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: 89ca39cfc099fd19c4f4b57d67b5f02ac22d9faacc5d01a74557a14506aa5503
|
4
|
+
data.tar.gz: 70334b3417d0648cc51c344198c3deaf6b91c24eb70ec7e5337c406d5a85934a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8f3aed3f0c089d5bc82c3b56a355732c5e6a57f430f543739b366dcd91f22b64e44dc98e280edb77194104ca69aafe42dd77e0495beec8ddb413a7570fd04f5
|
7
|
+
data.tar.gz: bb9998681664735ea63d0b30b952e94fc78c04d8aee903a60c4be142a81d4b692a4ca6594f0706d256d84f0e5917aeb328c95d0fc0de60404a6c169d7fe06021
|
data/README.md
CHANGED
@@ -24,9 +24,8 @@ If you want to use webpack features like [code splitting](https://webpack.js.org
|
|
24
24
|
|
25
25
|
You must already have node and yarn installed on your system. You will also need npx version 7.1.0 or later. Then:
|
26
26
|
|
27
|
-
1.
|
28
|
-
2. Run `./bin/
|
29
|
-
3. Run `./bin/rails javascript:install:[esbuild|rollup|webpack]`
|
27
|
+
1. Run `./bin/bundle add jsbundling-rails`
|
28
|
+
2. Run `./bin/rails javascript:install:[esbuild|rollup|webpack]`
|
30
29
|
|
31
30
|
Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp -j [esbuild|rollup|webpack]`.
|
32
31
|
|
@@ -37,10 +36,20 @@ Or, in Rails 7+, you can preconfigure your new application to use a specific bun
|
|
37
36
|
|
38
37
|
The default build script for esbuild relies on the `app/javascript/*.*` glob pattern to compile multiple entrypoints automatically. This glob pattern is not available by default on Windows, so you need to change the build script in `package.json` to manually list the entrypoints you wish to compile.
|
39
38
|
|
40
|
-
|
39
|
+
### Why does esbuild overwrite my application.css?
|
41
40
|
|
42
41
|
If you [import CSS](https://esbuild.github.io/content-types/#css-from-js) in your application.js while using esbuild, you'll be creating both an `app/assets/builds/application.js` _and_ `app/assets/builds/application.css` file when bundling. The latter can conflict with the `app/assets/builds/application.css` produced by [cssbundling-rails](https://github.com/rails/cssbundling-rails). The solution is to either change the output file for esbuild (and the references for that) or for cssbundling. Both are specified in `package.json`.
|
43
42
|
|
43
|
+
### How can I reference static assets in JavaScript code?
|
44
|
+
|
45
|
+
Suppose you have an image `app/javascript/images/example.png` that you need to reference in frontend code built with esbuild.
|
46
|
+
|
47
|
+
1. Create the image at `app/javascript/images/example.png`.
|
48
|
+
1. In `package.json`, under `"scripts"` and `"build"`, add the option `--loader:.png=file` to the esbuild script, which instructs esbuild to copy png files to the build directory.
|
49
|
+
1. When esbuild runs, it will copy the png file to something like `app/assets/builds/example-5SRKKTLZ.png`.
|
50
|
+
1. In frontend code, the image is available for import by its original name: `import Example from "../images/example.png"`.
|
51
|
+
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.
|
44
53
|
|
45
54
|
## License
|
46
55
|
|
data/lib/install/Procfile.dev
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
web: bin/rails server
|
1
|
+
web: unset PORT && 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 !
|
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"
|
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
@@ -13,6 +13,8 @@ end
|
|
13
13
|
|
14
14
|
if Rake::Task.task_defined?("test:prepare")
|
15
15
|
Rake::Task["test:prepare"].enhance(["javascript:build"])
|
16
|
+
elsif Rake::Task.task_defined?("spec:prepare")
|
17
|
+
Rake::Task["spec:prepare"].enhance(["javascript:build"])
|
16
18
|
elsif Rake::Task.task_defined?("db:test:prepare")
|
17
19
|
Rake::Task["db:test:prepare"].enhance(["javascript:build"])
|
18
20
|
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.0
|
4
|
+
version: 1.1.0
|
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: 2022-
|
11
|
+
date: 2022-12-14 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.3.26
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack.
|