jsbundling-rails 0.1.6 → 0.2.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 +7 -1
- data/lib/install/install.rb +3 -2
- 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 +4 -2
- data/lib/tasks/jsbundling/clean.rake +8 -0
- metadata +8 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b3886c122782f8cee3ae39317eee237ffe67500f2b6e8e4d0e46192d3214c5b
|
4
|
+
data.tar.gz: ede0353d4327d3dff14c7f119271cc40883d76e7bb2fdaf442ba8b508e33961b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 989e1c975ed68bcbb5ed1beb7fdda1b46ec7f8dd764ebf1c0871300541bd651fe74aefd8ac5c4379e347141d7e21553052d03f0ac31e3e580e72d9acabe92daa
|
7
|
+
data.tar.gz: e17204a1e4e953ada58ccead4e26b4f636075592b97f12b0bba0644d55a54431086b1ca944855f679db5c200870869a4a838371517097d873f2b0dfa67fe4858
|
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
|
data/lib/install/install.rb
CHANGED
@@ -7,7 +7,8 @@ if (sprockets_manifest_path = Rails.root.join("app/assets/config/manifest.js")).
|
|
7
7
|
end
|
8
8
|
|
9
9
|
if Rails.root.join(".gitignore").exist?
|
10
|
-
append_to_file(".gitignore", %(\n/app/assets/builds/*\n!/app/assets/builds/.keep\n
|
10
|
+
append_to_file(".gitignore", %(\n/app/assets/builds/*\n!/app/assets/builds/.keep\n))
|
11
|
+
append_to_file(".gitignore", %(\n/node_modules\n))
|
11
12
|
end
|
12
13
|
|
13
14
|
if (app_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist?
|
@@ -31,7 +32,7 @@ unless Rails.root.join("package.json").exist?
|
|
31
32
|
end
|
32
33
|
|
33
34
|
if Rails.root.join("Procfile.dev").exist?
|
34
|
-
append_to_file "Procfile.dev", "js: yarn build --watch"
|
35
|
+
append_to_file "Procfile.dev", "js: yarn build --watch\n"
|
35
36
|
else
|
36
37
|
say "Add default Procfile.dev"
|
37
38
|
copy_file "#{__dir__}/Procfile.dev", "Procfile.dev"
|
@@ -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
|
-
task :
|
4
|
-
system "yarn
|
3
|
+
task build: [ "yarn:install" ] do
|
4
|
+
unless system "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.
|
4
|
+
version: 0.2.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-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -24,21 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 6.0.0
|
27
|
-
|
28
|
-
name: sprockets-rails
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 2.0.0
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 2.0.0
|
41
|
-
description:
|
27
|
+
description:
|
42
28
|
email: david@loudthinking.com
|
43
29
|
executables: []
|
44
30
|
extensions: []
|
@@ -60,12 +46,13 @@ files:
|
|
60
46
|
- lib/jsbundling/engine.rb
|
61
47
|
- lib/jsbundling/version.rb
|
62
48
|
- lib/tasks/jsbundling/build.rake
|
49
|
+
- lib/tasks/jsbundling/clean.rake
|
63
50
|
- lib/tasks/jsbundling/install.rake
|
64
51
|
homepage: https://github.com/rails/jsbundling-rails
|
65
52
|
licenses:
|
66
53
|
- MIT
|
67
54
|
metadata: {}
|
68
|
-
post_install_message:
|
55
|
+
post_install_message:
|
69
56
|
rdoc_options: []
|
70
57
|
require_paths:
|
71
58
|
- lib
|
@@ -80,8 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
67
|
- !ruby/object:Gem::Version
|
81
68
|
version: '0'
|
82
69
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
84
|
-
signing_key:
|
70
|
+
rubygems_version: 3.2.22
|
71
|
+
signing_key:
|
85
72
|
specification_version: 4
|
86
73
|
summary: Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack.
|
87
74
|
test_files: []
|