jsbundling-rails 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 137e2a80465a741d5a59b07f3776f8de07461e782439f64f7a096ac9f46f4446
4
- data.tar.gz: 47ddd6de7ec38dbaaf5568c433723cf79c3f93a0b4409b580c85b7fceb5dbb01
3
+ metadata.gz: e87af17983ef465c2f92f63a3943df1ed2f1508eec23644f4134bdef5430ec27
4
+ data.tar.gz: de600a6cefeb7f190d1348f7edbe328d71fe13aeff2dd8903dcc4ff78a029a60
5
5
  SHA512:
6
- metadata.gz: 04222ea64e7bf09c63fef4dddabc1e9537960fecf6629dcca6c3417c31bbfc580d0de716c45b8c9638e60d8c80cee213aa2263b4c0ed2cebf47d49f47f48079f
7
- data.tar.gz: ef8f1a586d142d28d4399530a1cdc34065f59ebf23e0446d0fda349ceaefd82dc4377382b9e7ad53c412e89ec03e73562809ba81d05f5a9db47bcfee47776f97
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: unset PORT && bin/rails server
1
+ web: unset PORT && env RUBY_DEBUG_OPEN=true bin/rails server
2
2
  js: yarn build --watch
@@ -2,7 +2,7 @@ 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
7
  case `npx -v`.to_f
8
8
  when 7.1...8.0
@@ -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
  },
@@ -1,3 +1,3 @@
1
1
  module Jsbundling
2
- VERSION = "1.1.1"
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")
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.1.1
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-12-14 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.26
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.