jsbundling-rails 0.1.9 → 1.0.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 +15 -2
- data/lib/install/dev +6 -0
- data/lib/install/esbuild/install.rb +3 -2
- data/lib/install/rollup/install.rb +2 -1
- data/lib/install/rollup/rollup.config.js +2 -1
- data/lib/install/webpack/install.rb +2 -1
- data/lib/install/webpack/webpack.config.js +3 -1
- data/lib/jsbundling/version.rb +1 -1
- data/lib/tasks/jsbundling/clobber.rake +8 -0
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8748a7213762afebeb5520e47746553aa68e0958529d059124472da46700a06e
|
4
|
+
data.tar.gz: 65ed947a764debada1b0b512bdb0bacee11b4c985b582cff84b5a69c76672f1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a8ed6cbbf58b5d93c75e806fc8f12b55b2992f9309e05b8c428dcd0577e1e8791bd2fe17c44e49b7f5a6ae5633ecc51dc6b3e9ec571b5f110a690ea03144b94
|
7
|
+
data.tar.gz: 45d6b74a4dbee014d98196eb033cd9d06c94bfd6495eceb032e1bd84b2f4729baa3e413b37267ddc598f2c1c16485c4ac085486833eeb23455523097e8129b24
|
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
Use [esbuild](https://esbuild.github.io), [rollup.js](https://rollupjs.org), or [Webpack](https://webpack.js.org) to bundle your JavaScript, then deliver it via the asset pipeline in Rails. This gem provides installers to get you going with the bundler of your choice 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 the bundler 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)).
|
5
|
+
You develop using this approach by running the bundler 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)). You can also use `./bin/dev`, which will start both the Rails server and the JS build watcher (along with a CSS build watcher, if you're also using `cssbundling-rails`).
|
6
|
+
|
7
|
+
Whenever the bundler detects changes to any of the JavaScript files in your project, it'll bundle `app/javascript/application.js` into `app/assets/builds/application.js` (and all other entry points configured). You can refer to the build output in your layout using the standard asset pipeline approach with `<%= javascript_include_tag "application", defer: true %>`.
|
6
8
|
|
7
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.
|
8
10
|
|
@@ -12,7 +14,7 @@ If your testing library of choice does not define a `test:prepare` Rake task, en
|
|
12
14
|
|
13
15
|
That's it!
|
14
16
|
|
15
|
-
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).
|
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).
|
16
18
|
|
17
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).
|
18
20
|
|
@@ -28,6 +30,17 @@ You must already have node and yarn installed on your system. You will also need
|
|
28
30
|
Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp -j [esbuild|rollup|webpack]`.
|
29
31
|
|
30
32
|
|
33
|
+
## FAQ
|
34
|
+
|
35
|
+
### Is there a work-around for lack of glob syntax on Windows?
|
36
|
+
|
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
|
+
|
39
|
+
## Why does esbuild overwrite my application.css?
|
40
|
+
|
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
|
+
|
43
|
+
|
31
44
|
## License
|
32
45
|
|
33
46
|
JavaScript Bundling for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/install/dev
CHANGED
@@ -2,10 +2,11 @@ say "Install esbuild"
|
|
2
2
|
run "yarn add esbuild"
|
3
3
|
|
4
4
|
say "Add build script"
|
5
|
-
build_script = "esbuild app/javascript/*.* --bundle --outdir=app/assets/builds"
|
5
|
+
build_script = "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds"
|
6
6
|
|
7
7
|
if (`npx -v`.to_f < 7.1 rescue "Missing")
|
8
|
-
say %(Add "scripts": { "build": "#{build_script}" to your package.json), :green
|
8
|
+
say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
|
9
9
|
else
|
10
10
|
run %(npm set-script build "#{build_script}")
|
11
|
+
run %(yarn build)
|
11
12
|
end
|
@@ -6,7 +6,8 @@ say "Add build script"
|
|
6
6
|
build_script = "rollup -c rollup.config.js"
|
7
7
|
|
8
8
|
if (`npx -v`.to_f < 7.1 rescue "Missing")
|
9
|
-
say %(Add "scripts": { "build": "#{build_script}" to your package.json), :green
|
9
|
+
say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
|
10
10
|
else
|
11
11
|
run %(npm set-script build "#{build_script}")
|
12
|
+
run %(yarn build)
|
12
13
|
end
|
@@ -6,7 +6,8 @@ say "Add build script"
|
|
6
6
|
build_script = "webpack --config webpack.config.js"
|
7
7
|
|
8
8
|
if (`npx -v`.to_f < 7.1 rescue "Missing")
|
9
|
-
say %(Add "scripts": { "build": "#{build_script}" to your package.json), :green
|
9
|
+
say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
|
10
10
|
else
|
11
11
|
run %(npm set-script build "#{build_script}")
|
12
|
+
run %(yarn build)
|
12
13
|
end
|
@@ -1,13 +1,15 @@
|
|
1
1
|
const path = require("path")
|
2
|
-
const webpack = require(
|
2
|
+
const webpack = require("webpack")
|
3
3
|
|
4
4
|
module.exports = {
|
5
5
|
mode: "production",
|
6
|
+
devtool: "source-map",
|
6
7
|
entry: {
|
7
8
|
application: "./app/javascript/application.js"
|
8
9
|
},
|
9
10
|
output: {
|
10
11
|
filename: "[name].js",
|
12
|
+
sourceMapFilename: "[name].js.map",
|
11
13
|
path: path.resolve(__dirname, "app/assets/builds"),
|
12
14
|
},
|
13
15
|
plugins: [
|
data/lib/jsbundling/version.rb
CHANGED
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: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 6.0.0
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email: david@loudthinking.com
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
@@ -46,12 +46,13 @@ files:
|
|
46
46
|
- lib/jsbundling/engine.rb
|
47
47
|
- lib/jsbundling/version.rb
|
48
48
|
- lib/tasks/jsbundling/build.rake
|
49
|
+
- lib/tasks/jsbundling/clobber.rake
|
49
50
|
- lib/tasks/jsbundling/install.rake
|
50
51
|
homepage: https://github.com/rails/jsbundling-rails
|
51
52
|
licenses:
|
52
53
|
- MIT
|
53
54
|
metadata: {}
|
54
|
-
post_install_message:
|
55
|
+
post_install_message:
|
55
56
|
rdoc_options: []
|
56
57
|
require_paths:
|
57
58
|
- lib
|
@@ -66,8 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
67
|
- !ruby/object:Gem::Version
|
67
68
|
version: '0'
|
68
69
|
requirements: []
|
69
|
-
rubygems_version: 3.
|
70
|
-
signing_key:
|
70
|
+
rubygems_version: 3.2.32
|
71
|
+
signing_key:
|
71
72
|
specification_version: 4
|
72
73
|
summary: Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack.
|
73
74
|
test_files: []
|