jsbundling-rails 1.0.0 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -5
- data/lib/install/dev +2 -2
- data/lib/install/esbuild/install.rb +1 -1
- data/lib/install/webpack/webpack.config.js +1 -1
- data/lib/jsbundling/version.rb +1 -1
- data/lib/tasks/jsbundling/build.rake +3 -1
- data/lib/tasks/jsbundling/clobber.rake +4 -2
- 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: d5a44be3ec3ce6c70cdea6a949eb1161de8d93fc862fea729d6c69fd75507540
|
4
|
+
data.tar.gz: 8ac2566fb564e1b0f7c705c923bdd4cf19db68559d2549690ce388057aa56100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1fc1a7e5b48df676886d33b078a44b261312867ab16257900881924908ff5a669d27859673ece993c194e923e9d8d085da2ac101ee29928f648941382b87be2
|
7
|
+
data.tar.gz: '059d18f58411a82e4e68f2b2484232bb4da9135e0dcbf00cd64fc239ade89ff7bdbaabe199bf1fd48fc69af57414d55e60912201fe004c23be4e928f16140d13'
|
data/README.md
CHANGED
@@ -16,16 +16,16 @@ That's it!
|
|
16
16
|
|
17
17
|
You can configure your bundler options in the `build` script in `package.json` or via the installer-generated `rollup.config.js` for rollup.js or `webpack.config.json` for Webpack (esbuild does not have a default configuration format, and we don't intend to use esbuild as an API in order to hack around it).
|
18
18
|
|
19
|
-
If you're already using [`webpacker`](https://github.com/rails/webpacker) and you're wondering if you should migrate to `jsbundling-rails`, have a look at [the high-level comparison](./docs/comparison_with_webpacker.md).
|
19
|
+
If you're already using [`webpacker`](https://github.com/rails/webpacker) and you're wondering if you should migrate to `jsbundling-rails`, have a look at [the high-level comparison](./docs/comparison_with_webpacker.md). If you're looking to migrate from webpacker, see the [migration guide](https://github.com/rails/jsbundling-rails/blob/main/docs/switch_from_webpacker.md).
|
20
20
|
|
21
|
+
If you want to use webpack features like [code splitting](https://webpack.js.org/guides/code-splitting/) and [hot module reloading](https://webpack.js.org/concepts/hot-module-replacement/), consider using the official fork of `webpacker`, [`shakapacker`](https://github.com/shakacode/shakapacker).
|
21
22
|
|
22
23
|
## Installation
|
23
24
|
|
24
25
|
You must already have node and yarn installed on your system. You will also need npx version 7.1.0 or later. Then:
|
25
26
|
|
26
|
-
1.
|
27
|
-
2. Run `./bin/
|
28
|
-
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]`
|
29
29
|
|
30
30
|
Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp -j [esbuild|rollup|webpack]`.
|
31
31
|
|
@@ -36,10 +36,20 @@ Or, in Rails 7+, you can preconfigure your new application to use a specific bun
|
|
36
36
|
|
37
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.
|
38
38
|
|
39
|
-
|
39
|
+
### Why does esbuild overwrite my application.css?
|
40
40
|
|
41
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`.
|
42
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.
|
43
53
|
|
44
54
|
## License
|
45
55
|
|
data/lib/install/dev
CHANGED
@@ -2,7 +2,7 @@ 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
7
|
if (`npx -v`.to_f < 7.1 rescue "Missing")
|
8
8
|
say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
|
data/lib/jsbundling/version.rb
CHANGED
@@ -7,7 +7,9 @@ namespace :javascript do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
Rake::Task
|
10
|
+
if Rake::Task.task_defined?("assets:precompile")
|
11
|
+
Rake::Task["assets:precompile"].enhance(["javascript:build"])
|
12
|
+
end
|
11
13
|
|
12
14
|
if Rake::Task.task_defined?("test:prepare")
|
13
15
|
Rake::Task["test:prepare"].enhance(["javascript:build"])
|
@@ -1,8 +1,10 @@
|
|
1
1
|
namespace :javascript do
|
2
2
|
desc "Remove JavaScript builds"
|
3
3
|
task :clobber do
|
4
|
-
rm_rf Dir["app/assets/builds/[^.]*.js"], verbose: false
|
4
|
+
rm_rf Dir["app/assets/builds/[^.]*.{js,js.map}"], verbose: false
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
Rake::Task
|
8
|
+
if Rake::Task.task_defined?("assets:clobber")
|
9
|
+
Rake::Task["assets:clobber"].enhance(["javascript:clobber"])
|
10
|
+
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.0.3
|
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: 2022-06-19 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.14
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack.
|