railpack 1.1.0 → 1.2.1
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/README.md +1 -1
- data/lib/railpack/bundlers/rollup_bundler.rb +49 -0
- data/lib/railpack/bundlers/webpack_bundler.rb +49 -0
- data/lib/railpack/config.rb +7 -1
- data/lib/railpack/manager.rb +77 -3
- data/lib/railpack/version.rb +1 -1
- data/lib/railpack.rb +1 -0
- data/test/railpack_test.rb +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 65190ba06f3b41df3783655f29f50d8bddfc9e3380698a0c76f4c29f5e1b4841
|
|
4
|
+
data.tar.gz: e417b5906674f996132cdf84b92ee66cfad9c9e2d5e8b2917a2125dd5dc58965
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fbec7a17d5c6dcb309fc30d5880206ec0507d771b5f08c01bbed97bdaf4a35ba0402da65956723c6824ce5087f973b84c8dc2accf736d292d692b22cd44aee81
|
|
7
|
+
data.tar.gz: d064a8f46b8e517ee119ccb29ecbc13c9ab87f67291529dc5b3aae02a9cc6fe7a36b0652f604dbfb34ee7df813aef2e6a1987bff0348f130db9743b23cc29c04
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- 🚀 **Multiple Bundlers**: Bun, esbuild, Rollup support
|
|
7
|
+
- 🚀 **Multiple Bundlers**: Bun, esbuild, Rollup, Webpack support
|
|
8
8
|
- 🔧 **Unified API**: Same interface regardless of bundler
|
|
9
9
|
- 🎯 **Rails Integration**: Seamless asset pipeline integration
|
|
10
10
|
- ⚡ **Hot Module Replacement**: Development server with live reload
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Railpack
|
|
2
|
+
class RollupBundler < Bundler
|
|
3
|
+
def commands
|
|
4
|
+
{
|
|
5
|
+
build: "rollup",
|
|
6
|
+
watch: "rollup --watch",
|
|
7
|
+
build_dev: "rollup",
|
|
8
|
+
clean: "rm -rf dist/",
|
|
9
|
+
install: "npm install",
|
|
10
|
+
add: "npm install",
|
|
11
|
+
remove: "npm uninstall",
|
|
12
|
+
exec: "node",
|
|
13
|
+
version: "rollup --version"
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def build!(args = [])
|
|
18
|
+
execute!([commands[:build], *args])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def watch(args = [])
|
|
22
|
+
execute([commands[:watch], *args])
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def install!(args = [])
|
|
26
|
+
execute!([commands[:install], *args])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def add(*packages)
|
|
30
|
+
execute([commands[:add], *packages])
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def remove(*packages)
|
|
34
|
+
execute([commands[:remove], *packages])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def exec(*args)
|
|
38
|
+
execute([commands[:exec], *args])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def version
|
|
42
|
+
`#{commands[:version]}`.strip
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def installed?
|
|
46
|
+
system("#{commands[:version]} > /dev/null 2>&1")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Railpack
|
|
2
|
+
class WebpackBundler < Bundler
|
|
3
|
+
def commands
|
|
4
|
+
{
|
|
5
|
+
build: "webpack",
|
|
6
|
+
watch: "webpack --watch",
|
|
7
|
+
build_dev: "webpack",
|
|
8
|
+
clean: "rm -rf dist/",
|
|
9
|
+
install: "npm install",
|
|
10
|
+
add: "npm install",
|
|
11
|
+
remove: "npm uninstall",
|
|
12
|
+
exec: "node",
|
|
13
|
+
version: "webpack --version"
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def build!(args = [])
|
|
18
|
+
execute!([commands[:build], *args])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def watch(args = [])
|
|
22
|
+
execute([commands[:watch], *args])
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def install!(args = [])
|
|
26
|
+
execute!([commands[:install], *args])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def add(*packages)
|
|
30
|
+
execute([commands[:add], *packages])
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def remove(*packages)
|
|
34
|
+
execute([commands[:remove], *packages])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def exec(*args)
|
|
38
|
+
execute([commands[:exec], *args])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def version
|
|
42
|
+
`#{commands[:version]}`.strip
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def installed?
|
|
46
|
+
system("#{commands[:version]} > /dev/null 2>&1")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
data/lib/railpack/config.rb
CHANGED
|
@@ -137,11 +137,17 @@ module Railpack
|
|
|
137
137
|
"format" => "esm",
|
|
138
138
|
"sourcemap" => true
|
|
139
139
|
},
|
|
140
|
+
"webpack" => {
|
|
141
|
+
"mode" => "production",
|
|
142
|
+
"target" => "web"
|
|
143
|
+
},
|
|
140
144
|
"development" => {
|
|
141
145
|
"sourcemap" => true
|
|
142
146
|
},
|
|
143
147
|
"production" => {
|
|
144
|
-
"minify" => true
|
|
148
|
+
"minify" => true,
|
|
149
|
+
"sourcemap" => false,
|
|
150
|
+
"analyze_bundle" => false
|
|
145
151
|
}
|
|
146
152
|
}
|
|
147
153
|
end
|
data/lib/railpack/manager.rb
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
require 'digest'
|
|
2
|
+
require 'pathname'
|
|
3
|
+
|
|
1
4
|
module Railpack
|
|
2
5
|
class Manager
|
|
3
6
|
BUNDLERS = {
|
|
4
7
|
'bun' => BunBundler,
|
|
5
8
|
'esbuild' => EsbuildBundler,
|
|
6
|
-
'rollup' => RollupBundler
|
|
9
|
+
'rollup' => RollupBundler,
|
|
10
|
+
'webpack' => WebpackBundler
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
def initialize
|
|
@@ -12,16 +16,45 @@ module Railpack
|
|
|
12
16
|
|
|
13
17
|
# Unified API - delegate to the selected bundler
|
|
14
18
|
def build!(args = [])
|
|
19
|
+
start_time = Time.now
|
|
15
20
|
config = Railpack.config.for_environment(Rails.env)
|
|
16
21
|
Railpack.trigger_build_start(config)
|
|
17
22
|
|
|
18
23
|
begin
|
|
24
|
+
Railpack.logger.info "🚀 Starting #{config['bundler']} build for #{Rails.env} environment"
|
|
19
25
|
result = @bundler.build!(args)
|
|
20
|
-
|
|
26
|
+
duration = ((Time.now - start_time) * 1000).round(2)
|
|
27
|
+
|
|
28
|
+
# Calculate bundle size if output directory exists
|
|
29
|
+
bundle_size = calculate_bundle_size(config)
|
|
30
|
+
|
|
31
|
+
success_result = {
|
|
32
|
+
success: true,
|
|
33
|
+
config: config,
|
|
34
|
+
duration: duration,
|
|
35
|
+
bundle_size: bundle_size
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Railpack.logger.info "✅ Build completed successfully in #{duration}ms (#{bundle_size}kb)"
|
|
39
|
+
|
|
40
|
+
# Generate asset manifest for Rails
|
|
41
|
+
generate_asset_manifest(config)
|
|
42
|
+
|
|
43
|
+
Railpack.trigger_build_complete(success_result)
|
|
21
44
|
result
|
|
22
45
|
rescue => error
|
|
46
|
+
duration = ((Time.now - start_time) * 1000).round(2)
|
|
47
|
+
Railpack.logger.error "❌ Build failed after #{duration}ms: #{error.message}"
|
|
48
|
+
|
|
49
|
+
error_result = {
|
|
50
|
+
success: false,
|
|
51
|
+
error: error,
|
|
52
|
+
config: config,
|
|
53
|
+
duration: duration
|
|
54
|
+
}
|
|
55
|
+
|
|
23
56
|
Railpack.trigger_error(error)
|
|
24
|
-
Railpack.trigger_build_complete(
|
|
57
|
+
Railpack.trigger_build_complete(error_result)
|
|
25
58
|
raise
|
|
26
59
|
end
|
|
27
60
|
end
|
|
@@ -76,5 +109,46 @@ module Railpack
|
|
|
76
109
|
|
|
77
110
|
bundler_class.new(Railpack.config)
|
|
78
111
|
end
|
|
112
|
+
|
|
113
|
+
def calculate_bundle_size(config)
|
|
114
|
+
outdir = config['outdir']
|
|
115
|
+
return 'unknown' unless outdir && Dir.exist?(outdir)
|
|
116
|
+
|
|
117
|
+
total_size = 0
|
|
118
|
+
Dir.glob("#{outdir}/**/*.{js,css,map}").each do |file|
|
|
119
|
+
total_size += File.size(file) if File.file?(file)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
(total_size / 1024.0).round(2)
|
|
123
|
+
rescue
|
|
124
|
+
'unknown'
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def generate_asset_manifest(config)
|
|
128
|
+
outdir = config['outdir']
|
|
129
|
+
return unless outdir && Dir.exist?(outdir)
|
|
130
|
+
|
|
131
|
+
manifest = {}
|
|
132
|
+
|
|
133
|
+
# Find built assets
|
|
134
|
+
Dir.glob("#{outdir}/**/*.{js,css}").each do |file|
|
|
135
|
+
next unless File.file?(file)
|
|
136
|
+
relative_path = Pathname.new(file).relative_path_from(Pathname.new(outdir)).to_s
|
|
137
|
+
|
|
138
|
+
# Map logical names to physical files
|
|
139
|
+
if relative_path.include?('application') && relative_path.end_with?('.js')
|
|
140
|
+
manifest['application.js'] = relative_path
|
|
141
|
+
elsif relative_path.include?('application') && relative_path.end_with?('.css')
|
|
142
|
+
manifest['application.css'] = relative_path
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Write manifest for Rails asset pipeline
|
|
147
|
+
manifest_path = "#{outdir}/.sprockets-manifest-#{Digest::MD5.hexdigest(manifest.to_s)}.json"
|
|
148
|
+
File.write(manifest_path, JSON.pretty_generate(manifest))
|
|
149
|
+
Railpack.logger.debug "📄 Generated asset manifest: #{manifest_path}"
|
|
150
|
+
rescue => error
|
|
151
|
+
Railpack.logger.warn "⚠️ Failed to generate asset manifest: #{error.message}"
|
|
152
|
+
end
|
|
79
153
|
end
|
|
80
154
|
end
|
data/lib/railpack/version.rb
CHANGED
data/lib/railpack.rb
CHANGED
|
@@ -4,6 +4,7 @@ require_relative "railpack/bundler"
|
|
|
4
4
|
require_relative "railpack/bundlers/bun_bundler"
|
|
5
5
|
require_relative "railpack/bundlers/esbuild_bundler"
|
|
6
6
|
require_relative "railpack/bundlers/rollup_bundler"
|
|
7
|
+
require_relative "railpack/bundlers/webpack_bundler"
|
|
7
8
|
require_relative "railpack/config"
|
|
8
9
|
require_relative "railpack/manager"
|
|
9
10
|
|
data/test/railpack_test.rb
CHANGED
|
@@ -20,8 +20,10 @@ class RailpackTest < Minitest::Test
|
|
|
20
20
|
assert_includes Railpack::Manager::BUNDLERS.keys, 'bun'
|
|
21
21
|
assert_includes Railpack::Manager::BUNDLERS.keys, 'esbuild'
|
|
22
22
|
assert_includes Railpack::Manager::BUNDLERS.keys, 'rollup'
|
|
23
|
+
assert_includes Railpack::Manager::BUNDLERS.keys, 'webpack'
|
|
23
24
|
assert_equal Railpack::BunBundler, Railpack::Manager::BUNDLERS['bun']
|
|
24
25
|
assert_equal Railpack::EsbuildBundler, Railpack::Manager::BUNDLERS['esbuild']
|
|
25
26
|
assert_equal Railpack::RollupBundler, Railpack::Manager::BUNDLERS['rollup']
|
|
27
|
+
assert_equal Railpack::WebpackBundler, Railpack::Manager::BUNDLERS['webpack']
|
|
26
28
|
end
|
|
27
29
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: railpack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- 21tycoons LLC
|
|
@@ -41,6 +41,8 @@ files:
|
|
|
41
41
|
- lib/railpack/bundler.rb
|
|
42
42
|
- lib/railpack/bundlers/bun_bundler.rb
|
|
43
43
|
- lib/railpack/bundlers/esbuild_bundler.rb
|
|
44
|
+
- lib/railpack/bundlers/rollup_bundler.rb
|
|
45
|
+
- lib/railpack/bundlers/webpack_bundler.rb
|
|
44
46
|
- lib/railpack/config.rb
|
|
45
47
|
- lib/railpack/manager.rb
|
|
46
48
|
- lib/railpack/version.rb
|