jsbundling-rails 0.1.9 → 0.2.0

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: e5bde01f1cfb6e2fac2f04eda05dba4a31121ec4b45ed30c7fd1962499fd1b11
4
- data.tar.gz: 8db0f168b477075d235c36a66239eb9a37ade5c1a711ea7668efcfe18290e095
3
+ metadata.gz: 6b3886c122782f8cee3ae39317eee237ffe67500f2b6e8e4d0e46192d3214c5b
4
+ data.tar.gz: ede0353d4327d3dff14c7f119271cc40883d76e7bb2fdaf442ba8b508e33961b
5
5
  SHA512:
6
- metadata.gz: 30cc0891d989fc9cdc45784ac861d523c94d291a68430e64c753d718bf0e071eee8cd1c0ca64bbefca85110a2c56286c19917427dd4d59f9338dd4ca95796553
7
- data.tar.gz: 730a3011e7a338a682f004df50ea68950d50a88eba314a344d346497536f06d64670a36f2ff68f6a90595dd9e31b46fe01edbdf1d6c5f07b8544712f58c53b99
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)). 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 %>`.
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
@@ -1,3 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
+ if ! command -v foreman &> /dev/null
4
+ then
5
+ echo "Installing foreman..."
6
+ gem install foreman
7
+ fi
8
+
3
9
  foreman start -f Procfile.dev
@@ -2,10 +2,10 @@ say "Install esbuild"
2
2
  run "yarn add esbuild"
3
3
 
4
4
  say "Add build script"
5
- build_script = "esbuild app/javascript/*.* --bundle --outdir=app/assets/builds"
5
+ build_script = "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds"
6
6
 
7
7
  if (`npx -v`.to_f < 7.1 rescue "Missing")
8
- say %(Add "scripts": { "build": "#{build_script}" to your package.json), :green
8
+ say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
9
9
  else
10
10
  run %(npm set-script build "#{build_script}")
11
11
  end
@@ -6,7 +6,7 @@ say "Add build script"
6
6
  build_script = "rollup -c rollup.config.js"
7
7
 
8
8
  if (`npx -v`.to_f < 7.1 rescue "Missing")
9
- say %(Add "scripts": { "build": "#{build_script}" to your package.json), :green
9
+ say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
10
10
  else
11
11
  run %(npm set-script build "#{build_script}")
12
12
  end
@@ -5,7 +5,8 @@ export default {
5
5
  output: {
6
6
  file: "app/assets/builds/application.js",
7
7
  format: "es",
8
- inlineDynamicImports: true
8
+ inlineDynamicImports: true,
9
+ sourcemap: true
9
10
  },
10
11
  plugins: [
11
12
  resolve()
@@ -6,7 +6,7 @@ say "Add build script"
6
6
  build_script = "webpack --config webpack.config.js"
7
7
 
8
8
  if (`npx -v`.to_f < 7.1 rescue "Missing")
9
- say %(Add "scripts": { "build": "#{build_script}" to your package.json), :green
9
+ say %(Add "scripts": { "build": "#{build_script}" } to your package.json), :green
10
10
  else
11
11
  run %(npm set-script build "#{build_script}")
12
12
  end
@@ -1,13 +1,15 @@
1
1
  const path = require("path")
2
- const webpack = require('webpack')
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: [
@@ -1,3 +1,3 @@
1
1
  module Jsbundling
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  namespace :javascript do
2
2
  desc "Build your JavaScript bundle"
3
- task :build do
4
- unless system "yarn install && yarn build"
3
+ task build: [ "yarn:install" ] do
4
+ unless system "yarn build"
5
5
  raise "jsbundling-rails: Command build failed, ensure yarn is installed and `yarn build` runs without errors"
6
6
  end
7
7
  end
@@ -0,0 +1,8 @@
1
+ namespace :javascript do
2
+ desc "Remove JavaScript builds"
3
+ task :clean do
4
+ rm_rf Dir["app/assets/builds/[^.]*.js"], verbose: false
5
+ end
6
+ end
7
+
8
+ Rake::Task["assets:clean"].enhance(["javascript:clean"])
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.9
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-09-29 00:00:00.000000000 Z
11
+ date: 2021-11-15 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/clean.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.1.4
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: []