jsbundling-rails 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 709473c1e464dc72e16f938fba464de26e746a7c7a7bb599d4e55e5b5d3084e7
4
- data.tar.gz: ee9e7ac72bc4e5642b603773763b9d1dbf1ad11f5f21ea562125bbc26e68cb79
3
+ metadata.gz: 9762e5fde71d683691b621554e6067ac5c0bcb78bd776c7509ad60cc27326f47
4
+ data.tar.gz: 7e30a0361d250e21bddb58f78c4a384280e8367d1e0a7d4b724fecf4b6291124
5
5
  SHA512:
6
- metadata.gz: 0dd2e4765b05d630f0b278b0c7d5a6e909e8f42a630888763535cb19d6d51f92429767bb3da9960904e1e32ebb29747d060135fbffe6562b382dfad07d8f3071
7
- data.tar.gz: fbe17aa3c5ecae4d70643c6cd6e485b9c8df441de245fdc026b712d98da5494f428b68a4e92466819f3abfc904b3c7ac40f73fbb09637a465c37028a897a0583
6
+ metadata.gz: b96d6b4d31220c27f6ecb109bed9669029721c6f9b0e0e395497f97402c1f229d64211073fb494f7bc743808605b6b61447d7021e2cf6d4c450d0795da27c773
7
+ data.tar.gz: cf43abe223d0eadd63c4e698bb51eb4544a65a8ea21b9d4cd161b00434dae095eb9625dff7b82bea3823d288a5d60d87c3eb11c2cc74a1bd4437436aa3d2c9ea
data/README.md CHANGED
@@ -2,7 +2,7 @@
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)). 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/javascript.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 %>`.
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)). 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
6
 
7
7
  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
8
 
@@ -19,7 +19,7 @@ You must already have node and yarn installed on your system. Then:
19
19
 
20
20
  1. Add `jsbundling-rails` to your Gemfile with `gem 'jsbundling-rails'`
21
21
  2. Run `./bin/bundle install`
22
- 3. Run `./bin/rails javascript:[esbuild|rollup|webpack]:install`
22
+ 3. Run `./bin/rails javascript:install:[esbuild|rollup|webpack]`
23
23
 
24
24
  Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp -j [esbuild|rollup|webpack]`.
25
25
 
@@ -0,0 +1,2 @@
1
+ web: bin/rails server
2
+ js: yarn build --watch
data/lib/install/dev ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ foreman start -f Procfile.dev
@@ -1,3 +1,5 @@
1
- say "Create default package.json and install esbuild"
2
- copy_file "#{__dir__}/package.json", "package.json"
1
+ say "Install esbuild"
3
2
  run "yarn add esbuild"
3
+
4
+ say "Add build script"
5
+ run %(npm set-script build "esbuild app/javascript/*.* --bundle --outdir=app/assets/builds")
@@ -1,7 +1,7 @@
1
1
  say "Compile into app/assets/builds"
2
2
  empty_directory "app/assets/builds"
3
3
  keep_file "app/assets/builds"
4
- append_to_file "app/assets/config/manifest.js", %(//= link_tree ../builds .js\n)
4
+ append_to_file "app/assets/config/manifest.js", %(//= link_tree ../builds\n)
5
5
 
6
6
  if Rails.root.join(".gitignore").exist?
7
7
  append_to_file ".gitignore", %(/app/assets/builds\n)
@@ -21,3 +21,22 @@ unless (app_js_entrypoint_path = Rails.root.join("app/javascript/application.js"
21
21
  empty_directory app_js_entrypoint_path.parent.to_s
22
22
  copy_file "#{__dir__}/application.js", app_js_entrypoint_path
23
23
  end
24
+
25
+ unless Rails.root.join("package.json").exist?
26
+ say "Add default package.json"
27
+ copy_file "#{__dir__}/package.json", "package.json"
28
+ end
29
+
30
+ if Rails.root.join("Procfile.dev").exist?
31
+ append_to_file "Procfile.dev", "js: yarn build --watch"
32
+ else
33
+ say "Add default Procfile.dev"
34
+ copy_file "#{__dir__}/Procfile.dev", "Procfile.dev"
35
+
36
+ say "Ensure foreman is installed"
37
+ run "gem install foreman"
38
+ end
39
+
40
+ say "Add bin/dev to start foreman"
41
+ copy_file "#{__dir__}/dev", "bin/dev"
42
+ chmod "bin/dev", 0755, verbose: false
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "app",
3
+ "private": "true"
4
+ }
@@ -1,4 +1,6 @@
1
- say "Create default package.json and install rollup with config"
2
- copy_file "#{__dir__}/package.json", "package.json"
1
+ say "Install rollup with config"
3
2
  copy_file "#{__dir__}/rollup.config.js", "rollup.config.js"
4
3
  run "yarn add rollup @rollup/plugin-node-resolve"
4
+
5
+ say "Add build script"
6
+ run %(npm set-script build "rollup -c rollup.config.js")
@@ -1,4 +1,6 @@
1
- say "Create default package.json and install Webpack with config"
2
- copy_file "#{__dir__}/package.json", "package.json"
1
+ say "Install Webpack with config"
3
2
  copy_file "#{__dir__}/webpack.config.js", "webpack.config.js"
4
3
  run "yarn add webpack webpack-cli"
4
+
5
+ say "Add build script"
6
+ run %(npm set-script build "webpack --config webpack.config.js")
@@ -1,3 +1,3 @@
1
1
  module Jsbundling
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  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: 0.1.1
4
+ version: 0.1.2
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: 2021-09-06 00:00:00.000000000 Z
11
+ date: 2021-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -32,15 +32,15 @@ extra_rdoc_files: []
32
32
  files:
33
33
  - MIT-LICENSE
34
34
  - README.md
35
+ - lib/install/Procfile.dev
35
36
  - lib/install/application.js
37
+ - lib/install/dev
36
38
  - lib/install/esbuild/install.rb
37
- - lib/install/esbuild/package.json
38
39
  - lib/install/install.rb
40
+ - lib/install/package.json
39
41
  - lib/install/rollup/install.rb
40
- - lib/install/rollup/package.json
41
42
  - lib/install/rollup/rollup.config.js
42
43
  - lib/install/webpack/install.rb
43
- - lib/install/webpack/package.json
44
44
  - lib/install/webpack/webpack.config.js
45
45
  - lib/jsbundling-rails.rb
46
46
  - lib/jsbundling/engine.rb
@@ -1,7 +0,0 @@
1
- {
2
- "name": "app",
3
- "private": "true",
4
- "scripts": {
5
- "build": "esbuild app/javascript/*.* --bundle --outdir=app/assets/builds"
6
- }
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "name": "app",
3
- "private": "true",
4
- "scripts": {
5
- "build": "rollup -c rollup.config.js"
6
- }
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "name": "app",
3
- "private": "true",
4
- "scripts": {
5
- "build": "webpack --config webpack.config.js"
6
- }
7
- }