jsbundling-rails 0.1.7 → 0.2.1
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 +15 -2
- data/lib/install/dev +6 -0
- data/lib/install/esbuild/install.rb +7 -1
- data/lib/install/rollup/install.rb +7 -1
- data/lib/install/rollup/rollup.config.js +2 -1
- data/lib/install/webpack/install.rb +7 -1
- data/lib/install/webpack/webpack.config.js +3 -1
- data/lib/jsbundling/version.rb +1 -1
- data/lib/tasks/jsbundling/build.rake +3 -1
- data/lib/tasks/jsbundling/clobber.rake +6 -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: 2c0462a5cd60b4d9f11d5f1b422675b6e2057a05389833bd81246d3242847dfe
|
4
|
+
data.tar.gz: 847fd31b04ad34182e10dcf4e5157055dafae83bcf13c435cd6ee4cea7fcf440
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 954a585f3da1bd9e957698438462b977539cf6ba59fa2957f9d4fd4e277d6284ce197138af964eef32bff893b4567b227fb6812b28b2a48eb2bee48702303828
|
7
|
+
data.tar.gz: 924e4d2a47c5bbed32f848264ecb8cb67e39e899c8d25e647ca110dec7dfa142c3a7228678da4492f8fceb511f6a4c3ce638d18181783f2efa1b0125bd8a5a27
|
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.js` 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,4 +2,10 @@ say "Install esbuild"
|
|
2
2
|
run "yarn add esbuild"
|
3
3
|
|
4
4
|
say "Add build script"
|
5
|
-
|
5
|
+
build_script = "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds"
|
6
|
+
|
7
|
+
if (`npx -v`.to_f < 7.1 rescue "Missing")
|
8
|
+
say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
|
9
|
+
else
|
10
|
+
run %(npm set-script build "#{build_script}")
|
11
|
+
end
|
@@ -3,4 +3,10 @@ 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
|
-
|
6
|
+
build_script = "rollup -c rollup.config.js"
|
7
|
+
|
8
|
+
if (`npx -v`.to_f < 7.1 rescue "Missing")
|
9
|
+
say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
|
10
|
+
else
|
11
|
+
run %(npm set-script build "#{build_script}")
|
12
|
+
end
|
@@ -3,4 +3,10 @@ copy_file "#{__dir__}/webpack.config.js", "webpack.config.js"
|
|
3
3
|
run "yarn add webpack webpack-cli"
|
4
4
|
|
5
5
|
say "Add build script"
|
6
|
-
|
6
|
+
build_script = "webpack --config webpack.config.js"
|
7
|
+
|
8
|
+
if (`npx -v`.to_f < 7.1 rescue "Missing")
|
9
|
+
say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
|
10
|
+
else
|
11
|
+
run %(npm set-script build "#{build_script}")
|
12
|
+
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
@@ -1,7 +1,9 @@
|
|
1
1
|
namespace :javascript do
|
2
2
|
desc "Build your JavaScript bundle"
|
3
3
|
task :build do
|
4
|
-
system "yarn install && yarn build"
|
4
|
+
unless system "yarn install && yarn build"
|
5
|
+
raise "jsbundling-rails: Command build failed, ensure yarn is installed and `yarn build` runs without errors"
|
6
|
+
end
|
5
7
|
end
|
6
8
|
end
|
7
9
|
|
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.1
|
4
|
+
version: 0.2.1
|
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-11-17 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.22
|
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: []
|