rspack_rails 0.2.0 → 0.3.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: b7f84e6f9280bcf6d3fbd54f2a3a267a817e7c333d4c89a70c8e171b477f3e85
4
- data.tar.gz: '09e2d5eb77331777f33a1b58478ba1bac7774ffe83308b0f97236653fb80f534'
3
+ metadata.gz: d38b564f0260e86ab95775b11d6435853d520922028c59c3acce6c7ad1af639b
4
+ data.tar.gz: 062aff2e71411f542808ec77ed5054935040ec6018a1a3839ba374b2cfd10dc2
5
5
  SHA512:
6
- metadata.gz: 79928a7186a0b752296a5d82cf5e570ce87730a24ce2c1c515c4490be4585fe512790b68b4bdef81f9a76c608a73a615d4db75d7891889092f1a8a56a7a76e66
7
- data.tar.gz: 11660d1b0a381e43a789b8b5b2b92593784755cbfda2d00f32f1646b784dd39d959329fa2845febf900e4e6af38e4879c816832ecb5f2c944e1f8d6241ffbe47
6
+ metadata.gz: 0d1ab868d62a2ce92bb0cf1f330f4113e311658fea8e0174f50ef73c001fa7f67ccb580094bdb7f805606026536b7a3580ece740dd4f88d3b946baa32e84883a
7
+ data.tar.gz: c919c924784fb9885e4b8c9b8ae5db4255475adb9fd915a71e1a7a882a20bd02d6cf6c0eb2120928d7c89a0b214676ec3ddf92b1e785f48a89059e5e9ed02bd5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2026-11-13
4
+
5
+ - Multiple entry points: every `app/javascript/entrypoints/*.{js,ts}` becomes a bundle named after the file; `application.ts` works as the main entry
6
+ - `rspack:doctor` lists entry points and reports any that are not built
7
+ - Fix: the dev server no longer writes `*.hot-update.js` files into `app/assets/builds`
8
+ - Existing apps: re-run `bin/rails rspack:install` and accept the new `rspack.config.mjs`
9
+
3
10
  ## [0.2.0] - 2026-11-13
4
11
 
5
12
  - CSS imported from JavaScript is extracted to `app/assets/builds/<entry>.bundle.css` and hot-reloaded under `rspack serve`; `*.module.css` are CSS modules
data/README.md CHANGED
@@ -63,6 +63,23 @@ Under `rspack serve`, editing a controller or adding a new one hot-swaps it in t
63
63
 
64
64
  If `application.js` imported `./controllers` (the stimulus-rails index), the installer switches it to `./controllers/autoload`. stimulus-rails may still rewrite `controllers/index.js` when you run `bin/rails generate stimulus`, but nothing imports that file any more.
65
65
 
66
+ ### Multiple entry points
67
+
68
+ Besides `app/javascript/application.js` (or `.ts`), every file in `app/javascript/entrypoints/` becomes its own bundle, named after the file:
69
+
70
+ ```
71
+ app/javascript/application.js -> application.js
72
+ app/javascript/entrypoints/admin.ts -> admin.js
73
+ app/javascript/entrypoints/checkout.js -> checkout.js (+ checkout.bundle.css if it imports CSS)
74
+ ```
75
+
76
+ ```erb
77
+ <%# app/views/layouts/admin.html.erb %>
78
+ <%= rspack_javascript_tag "admin" %>
79
+ ```
80
+
81
+ Each bundle is self-contained, so load one entry per page (for example one per layout). Restart the dev server after adding a new entry point.
82
+
66
83
  ### CSS
67
84
 
68
85
  Import CSS from your JavaScript and rspack extracts it to `app/assets/builds/<entry>.bundle.css`:
@@ -124,6 +141,8 @@ The required Node.js version comes from the `engines` field of the installed `@r
124
141
  ```bash
125
142
  bin/setup
126
143
  bundle exec rake # specs + rubocop
144
+ bin/integration # new Rails app + every installer, build, doctor and precompile
145
+ bin/integration "~> 7.2.0" # against a specific Rails version
127
146
  ```
128
147
 
129
148
  ## License
@@ -1,3 +1,4 @@
1
+ import fs from "node:fs";
1
2
  import path from "node:path";
2
3
  import { fileURLToPath } from "node:url";
3
4
  import { defineConfig } from "@rspack/cli";
@@ -12,51 +13,66 @@ const isProduction =
12
13
  const host = process.env.RSPACK_DEV_SERVER_HOST || "localhost";
13
14
  const port = Number(process.env.RSPACK_DEV_SERVER_PORT || 3036);
14
15
 
16
+ // Entries: app/javascript/application.{js,ts} plus every file in
17
+ // app/javascript/entrypoints/, named after the file (admin.js -> "admin").
18
+ // Restart the dev server after adding an entrypoint.
19
+ const entry = {};
20
+ for (const ext of ["js", "ts"]) {
21
+ const file = `./app/javascript/application.${ext}`;
22
+ if (!entry.application && fs.existsSync(path.resolve(root, file))) entry.application = file;
23
+ }
24
+ const entrypointsDir = path.resolve(root, "app/javascript/entrypoints");
25
+ if (fs.existsSync(entrypointsDir)) {
26
+ for (const file of fs.readdirSync(entrypointsDir).sort()) {
27
+ const match = file.match(/^(.+)\.(js|ts)$/);
28
+ if (match) entry[match[1]] = `./app/javascript/entrypoints/${file}`;
29
+ }
30
+ }
31
+
15
32
  export default defineConfig({
16
33
  mode: isProduction ? "production" : "development",
17
34
  devtool: "source-map",
18
- entry: {
19
- application: "./app/javascript/application.js",
20
- },
35
+ entry,
21
36
  output: {
22
37
  path: path.resolve(root, "app/assets/builds"),
23
38
  filename: "[name].js",
24
39
  // ".digested" tells Propshaft the file is already fingerprinted.
25
- chunkFilename: "[name]-[contenthash].digested.js",
26
- // CSS imported from JavaScript. ".bundle" avoids clashing with
27
- // app/assets/stylesheets/application.css in Propshaft.
28
- cssFilename: "[name].bundle.css",
29
- cssChunkFilename: "[name]-[contenthash].digested.css",
40
+ chunkFilename: "[name]-[contenthash].digested.js",
41
+ // CSS imported from JavaScript. ".bundle" avoids clashing with
42
+ // app/assets/stylesheets/application.css in Propshaft.
43
+ cssFilename: "[name].bundle.css",
44
+ cssChunkFilename: "[name]-[contenthash].digested.css",
30
45
  // Under `rspack serve`, chunks and hot updates load from the dev server.
31
46
  publicPath: isDevServer ? `http://${host}:${port}/` : "/assets/",
32
47
  },
33
- resolve: {
34
- extensions: ["...", ".ts"],
35
- },
36
- module: {
37
- rules: [
38
- {
39
- // Transpile TypeScript with Rspack's built-in SWC (no type checking).
40
- test: /\.ts$/,
41
- exclude: /node_modules/,
42
- loader: "builtin:swc-loader",
43
- options: { jsc: { parser: { syntax: "typescript" } } },
44
- type: "javascript/auto",
45
- },
46
- {
47
- // Native CSS; *.module.css files become CSS modules.
48
- test: /\.css$/,
49
- type: "css/auto",
50
- },
51
- ],
52
- },
48
+ resolve: {
49
+ extensions: ["...", ".ts"],
50
+ },
51
+ module: {
52
+ rules: [
53
+ {
54
+ // Transpile TypeScript with Rspack's built-in SWC (no type checking).
55
+ test: /\.ts$/,
56
+ exclude: /node_modules/,
57
+ loader: "builtin:swc-loader",
58
+ options: { jsc: { parser: { syntax: "typescript" } } },
59
+ type: "javascript/auto",
60
+ },
61
+ {
62
+ // Native CSS; *.module.css files become CSS modules.
63
+ test: /\.css$/,
64
+ type: "css/auto",
65
+ },
66
+ ],
67
+ },
53
68
  devServer: {
54
69
  host,
55
70
  port,
56
71
  hot: true,
57
72
  // Keep app/assets/builds current while the dev server runs, so Propshaft
58
- // (and `stylesheet_link_tag :app`) never serve a stale bundle.
59
- devMiddleware: { writeToDisk: true },
73
+ // (and `stylesheet_link_tag :app`) never serve a stale bundle. Hot update
74
+ // files stay in memory so they never reach public/assets.
75
+ devMiddleware: { writeToDisk: (file) => !/\.hot-update\./.test(file) },
60
76
  allowedHosts: "all",
61
77
  headers: { "Access-Control-Allow-Origin": "*" },
62
78
  client: {
@@ -4,6 +4,7 @@ require "json"
4
4
  require "open3"
5
5
  require "pathname"
6
6
  require_relative "node_version"
7
+ require_relative "entrypoints"
7
8
 
8
9
  module RspackRails
9
10
  # Inspects a Rails app's rspack setup and reports what is missing.
@@ -91,17 +92,17 @@ module RspackRails
91
92
  end
92
93
 
93
94
  def entry_check
94
- return Check.new(:ok, "Entry point", "app/javascript/application.js") if exist?("app/javascript/application.js")
95
+ return Check.new(:ok, "Entry points", entrypoints.keys.join(", ")) if entrypoints.any?
95
96
 
96
- Check.new(:error, "Entry point", "app/javascript/application.js is missing",
97
- "Create it, or point `entry` in rspack.config.mjs at your entry file")
97
+ Check.new(:error, "Entry points", "none found",
98
+ "Create app/javascript/application.js or a file in app/javascript/entrypoints/")
98
99
  end
99
100
 
100
101
  def build_check
101
- built = @root.join("app/assets/builds/application.js")
102
- return Check.new(:ok, "Build output", "app/assets/builds/application.js (#{built.size} bytes)") if built.exist?
102
+ missing = entrypoints.keys.reject { |name| exist?("app/assets/builds/#{name}.js") }
103
+ return Check.new(:ok, "Build output", "app/assets/builds has #{entrypoints.keys.join(", ")}") if missing.empty?
103
104
 
104
- Check.new(:warn, "Build output", "app/assets/builds/application.js not built yet",
105
+ Check.new(:warn, "Build output", "not built yet: #{missing.join(", ")}",
105
106
  "Run `bin/rails rspack:build` (only needed without the dev server)")
106
107
  end
107
108
 
@@ -186,6 +187,10 @@ module RspackRails
186
187
  nil
187
188
  end
188
189
 
190
+ def entrypoints
191
+ @entrypoints ||= Entrypoints.discover(@root)
192
+ end
193
+
189
194
  def package_manager
190
195
  @package_manager ||= PackageManager.detect(@root)
191
196
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+
5
+ module RspackRails
6
+ # Mirrors the entry discovery in the generated rspack.config.mjs:
7
+ # app/javascript/application.{js,ts} plus every
8
+ # app/javascript/entrypoints/*.{js,ts}, named after the file.
9
+ module Entrypoints
10
+ EXTENSIONS = %w[js ts].freeze
11
+
12
+ module_function
13
+
14
+ # => { "application" => "app/javascript/application.js", "admin" => "app/javascript/entrypoints/admin.js" }
15
+ def discover(root)
16
+ root = Pathname(root)
17
+ entries = {}
18
+ main = EXTENSIONS.map { |ext| "app/javascript/application.#{ext}" }.find { |path| root.join(path).file? }
19
+ entries["application"] = main if main
20
+
21
+ Dir.glob("app/javascript/entrypoints/*.{#{EXTENSIONS.join(",")}}", base: root).sort.each do |path|
22
+ entries[File.basename(path, ".*")] = path
23
+ end
24
+ entries
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RspackRails
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/rspack_rails.rb CHANGED
@@ -4,6 +4,7 @@ require_relative "rspack_rails/version"
4
4
  require_relative "rspack_rails/package_manager"
5
5
  require_relative "rspack_rails/configuration"
6
6
  require_relative "rspack_rails/dev_server"
7
+ require_relative "rspack_rails/entrypoints"
7
8
 
8
9
  # Rspack integration for Rails: rake tasks, installer and view helpers.
9
10
  module RspackRails
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspack_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tungnt
@@ -57,6 +57,7 @@ files:
57
57
  - lib/rspack_rails/configuration.rb
58
58
  - lib/rspack_rails/dev_server.rb
59
59
  - lib/rspack_rails/doctor.rb
60
+ - lib/rspack_rails/entrypoints.rb
60
61
  - lib/rspack_rails/helper.rb
61
62
  - lib/rspack_rails/node_version.rb
62
63
  - lib/rspack_rails/package_manager.rb