jsbundling-rails 1.0.3 → 1.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: d5a44be3ec3ce6c70cdea6a949eb1161de8d93fc862fea729d6c69fd75507540
4
- data.tar.gz: 8ac2566fb564e1b0f7c705c923bdd4cf19db68559d2549690ce388057aa56100
3
+ metadata.gz: e87af17983ef465c2f92f63a3943df1ed2f1508eec23644f4134bdef5430ec27
4
+ data.tar.gz: de600a6cefeb7f190d1348f7edbe328d71fe13aeff2dd8903dcc4ff78a029a60
5
5
  SHA512:
6
- metadata.gz: a1fc1a7e5b48df676886d33b078a44b261312867ab16257900881924908ff5a669d27859673ece993c194e923e9d8d085da2ac101ee29928f648941382b87be2
7
- data.tar.gz: '059d18f58411a82e4e68f2b2484232bb4da9135e0dcbf00cd64fc239ade89ff7bdbaabe199bf1fd48fc69af57414d55e60912201fe004c23be4e928f16140d13'
6
+ metadata.gz: 06f0040b3476411f6bcb1bfcef1280763161c53a2dddb9087c180f31e8b360992dcb6191aa04c08755298d69b3f5671a5583a435b1a988b55fca2370a794958f
7
+ data.tar.gz: 18f37485ec256760ed0343d820da6798b6e2f358d4db3c9a653f4d95ccc961c11db4380c25add8d2e6776bcbc058e56229563c7d4fb261b53efc9f9f795335fb
data/README.md CHANGED
@@ -8,9 +8,7 @@ Whenever the bundler detects changes to any of the JavaScript files in your proj
8
8
 
9
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.
10
10
 
11
- This also happens in testing where the bundler attaches to the `test:prepare` task to ensure the JavaScript has been bundled before testing commences. (Note that this currently only applies to rails `test:*` tasks (like `test:all` or `test:controllers`), not "rails test", as that doesn't load `test:prepare`).
12
-
13
- If your testing library of choice does not define a `test:prepare` Rake task, ensure that your test suite runs `javascript:build` to bundle JavaScript before testing commences.
11
+ This also happens in testing where the bundler attaches to the `test:prepare` task to ensure the JavaScript has been bundled before testing commences. If your testing library of choice does not call the `test:prepare` Rake task, ensure that your test suite runs `javascript:build` to bundle JavaScript before testing commences.
14
12
 
15
13
  That's it!
16
14
 
@@ -22,10 +20,15 @@ If you want to use webpack features like [code splitting](https://webpack.js.org
22
20
 
23
21
  ## Installation
24
22
 
25
- You must already have node and yarn installed on your system. You will also need npx version 7.1.0 or later. Then:
23
+ You must already have node and yarn installed on your system. You will also need npx version 7.1.0 or later. Then run:
24
+
25
+ ```
26
+ ./bin/bundle add jsbundling-rails
27
+ ```
26
28
 
27
- 1. Run `./bin/bundle add jsbundling-rails`
28
- 2. Run `./bin/rails javascript:install:[esbuild|rollup|webpack]`
29
+ ```
30
+ ./bin/rails javascript:install:[esbuild|rollup|webpack]
31
+ ```
29
32
 
30
33
  Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp -j [esbuild|rollup|webpack]`.
31
34
 
@@ -45,11 +48,13 @@ If you [import CSS](https://esbuild.github.io/content-types/#css-from-js) in you
45
48
  Suppose you have an image `app/javascript/images/example.png` that you need to reference in frontend code built with esbuild.
46
49
 
47
50
  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`.
51
+ 1. In `package.json`, under `"scripts"` and `"build"`, add the additional arguments:
52
+ * `--loader:.png=file` This instructs esbuild to copy png files to the build directory.
53
+ * `--asset-names=[name]-[hash].digested` This tells esbuild to append `.digested` to the file name so that sprockets or propshaft will not append an additional digest hash to the file.
54
+ 1. When esbuild runs, it will copy the png file to something like `app/assets/builds/example-5SRKKTLZ.digested.png`.
50
55
  1. In frontend code, the image is available for import by its original name: `import Example from "../images/example.png"`.
51
56
  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.
57
+ 1. The path of the image resolves to `/assets/example-5SRKKTLZ.digested.png`, which is served by the asset pipeline.
53
58
 
54
59
  ## License
55
60
 
@@ -1,2 +1,2 @@
1
- web: bin/rails server -p 3000
1
+ web: unset PORT && env RUBY_DEBUG_OPEN=true bin/rails server
2
2
  js: yarn build --watch
data/lib/install/dev CHANGED
@@ -1,9 +1,8 @@
1
- #!/usr/bin/env bash
1
+ #!/usr/bin/env sh
2
2
 
3
- if ! foreman version &> /dev/null
4
- then
3
+ if ! gem list foreman -i --silent; then
5
4
  echo "Installing foreman..."
6
5
  gem install foreman
7
6
  fi
8
7
 
9
- foreman start -f Procfile.dev "$@"
8
+ exec foreman start -f Procfile.dev "$@"
@@ -2,11 +2,15 @@ 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 --public-path=assets"
5
+ build_script = "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=/assets"
6
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
7
+ case `npx -v`.to_f
8
+ when 7.1...8.0
10
9
  run %(npm set-script build "#{build_script}")
11
10
  run %(yarn build)
11
+ when (8.0..)
12
+ run %(npm pkg set scripts.build="#{build_script}")
13
+ run %(yarn build)
14
+ else
15
+ say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
12
16
  end
@@ -3,11 +3,15 @@ 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
- build_script = "rollup -c rollup.config.js"
6
+ build_script = "rollup -c --bundleConfigAsCjs rollup.config.js"
7
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
8
+ case `npx -v`.to_f
9
+ when 7.1...8.0
11
10
  run %(npm set-script build "#{build_script}")
12
11
  run %(yarn build)
12
+ when (8.0..)
13
+ run %(npm pkg set scripts.build="#{build_script}")
14
+ run %(yarn build)
15
+ else
16
+ say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
13
17
  end
@@ -4,7 +4,7 @@ export default {
4
4
  input: "app/javascript/application.js",
5
5
  output: {
6
6
  file: "app/assets/builds/application.js",
7
- format: "es",
7
+ format: "iife",
8
8
  inlineDynamicImports: true,
9
9
  sourcemap: true
10
10
  },
@@ -5,9 +5,13 @@ run "yarn add webpack webpack-cli"
5
5
  say "Add build script"
6
6
  build_script = "webpack --config webpack.config.js"
7
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
8
+ case `npx -v`.to_f
9
+ when 7.1...8.0
11
10
  run %(npm set-script build "#{build_script}")
12
11
  run %(yarn build)
12
+ when (8.0..)
13
+ run %(npm pkg set scripts.build="#{build_script}")
14
+ run %(yarn build)
15
+ else
16
+ say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
13
17
  end
@@ -1,3 +1,3 @@
1
1
  module Jsbundling
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -1,10 +1,18 @@
1
1
  namespace :javascript do
2
+ desc "Install JavaScript dependencies"
3
+ task :install do
4
+ unless system "yarn install"
5
+ raise "jsbundling-rails: Command install failed, ensure yarn is installed"
6
+ end
7
+ end
8
+
2
9
  desc "Build your JavaScript bundle"
3
- task :build do
4
- unless system "yarn install && yarn build"
5
- raise "jsbundling-rails: Command build failed, ensure yarn is installed and `yarn build` runs without errors"
10
+ build_task = task :build do
11
+ unless system "yarn build"
12
+ raise "jsbundling-rails: Command build failed, ensure `yarn build` runs without errors"
6
13
  end
7
14
  end
15
+ build_task.prereqs << :install unless ENV["SKIP_YARN_INSTALL"]
8
16
  end
9
17
 
10
18
  if Rake::Task.task_defined?("assets:precompile")
@@ -13,6 +21,8 @@ end
13
21
 
14
22
  if Rake::Task.task_defined?("test:prepare")
15
23
  Rake::Task["test:prepare"].enhance(["javascript:build"])
24
+ elsif Rake::Task.task_defined?("spec:prepare")
25
+ Rake::Task["spec:prepare"].enhance(["javascript:build"])
16
26
  elsif Rake::Task.task_defined?("db:test:prepare")
17
27
  Rake::Task["db:test:prepare"].enhance(["javascript:build"])
18
28
  end
@@ -1,7 +1,7 @@
1
1
  namespace :javascript do
2
2
  desc "Remove JavaScript builds"
3
3
  task :clobber do
4
- rm_rf Dir["app/assets/builds/[^.]*.{js,js.map}"], verbose: false
4
+ rm_rf Dir["app/assets/builds/**/[^.]*.{js,js.map}"], verbose: false
5
5
  end
6
6
  end
7
7
 
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.3
4
+ version: 1.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: 2022-06-19 00:00:00.000000000 Z
11
+ date: 2023-06-18 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.3.14
70
+ rubygems_version: 3.4.10
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack.