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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +19 -0
- data/lib/install/rspack.config.mjs +46 -30
- data/lib/rspack_rails/doctor.rb +11 -6
- data/lib/rspack_rails/entrypoints.rb +27 -0
- data/lib/rspack_rails/version.rb +1 -1
- data/lib/rspack_rails.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d38b564f0260e86ab95775b11d6435853d520922028c59c3acce6c7ad1af639b
|
|
4
|
+
data.tar.gz: 062aff2e71411f542808ec77ed5054935040ec6018a1a3839ba374b2cfd10dc2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
35
|
-
},
|
|
36
|
-
module: {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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: {
|
data/lib/rspack_rails/doctor.rb
CHANGED
|
@@ -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
|
|
95
|
+
return Check.new(:ok, "Entry points", entrypoints.keys.join(", ")) if entrypoints.any?
|
|
95
96
|
|
|
96
|
-
Check.new(:error, "Entry
|
|
97
|
-
"Create
|
|
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
|
-
|
|
102
|
-
return Check.new(:ok, "Build output", "app/assets/builds
|
|
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", "
|
|
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
|
data/lib/rspack_rails/version.rb
CHANGED
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.
|
|
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
|