condenser-rails 1.2 → 2.0.0.rc1

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: 85ea54efa8084fec3370c9109968566c25fc42e2c1dda0117af935509cdd3d04
4
- data.tar.gz: 85d88db655be386be3fb03bcd0fdaf176b032a41d6ef0ee5025de6bfb3215bea
3
+ metadata.gz: af5ea6490579f3e2d0ad960b7b105ead8d9e65841d5c3554275f77593d9dea40
4
+ data.tar.gz: 6b3be923f9411e60fa19c16e4e9087210d8251247066e7b560dc8c6f8406ea58
5
5
  SHA512:
6
- metadata.gz: 32f2939a3411dd310790767e50da0dc331421752082a4f548d7e1c5dc2dffa82e3b5ea559afa9d570fc5398f0eaaa933b61184fad727b11c59162441aa390f69
7
- data.tar.gz: bdcb847ece9af49935ec5497d053912e7114871463f1af9573e73441c7500609d7a5a80cd675d7971ae16219e84c76c7e15a3b7fe669f3bc7dcc1c58d2028719
6
+ metadata.gz: c5b51b307cff02a363c48855bc66741e31b942d8c8ca70a756a1409637d12e6b4a9883fdcc459141d31bba40995cd84bda2932eb321aac8f395ccb1da329ba8d
7
+ data.tar.gz: 8a6c9793fc11a839dd02898ad2823b57ef051fa3eeb031efdd7bec105d368a145f35466b1d2eed826e811e4da31fc04a51c0f5955891d0cc7ea941b89f0d1edd
data/README.md CHANGED
@@ -2,15 +2,57 @@
2
2
 
3
3
  Provides Condenser integration for the Rails Asset Pipeline.
4
4
 
5
+ Requires Condenser 2.0, Ruby 3.3 or newer, Rails 8.0 or newer, and Node
6
+ wherever assets are compiled. Upgrading from an earlier version? See
7
+ [Upgrading to Condenser 2](#upgrading-to-condenser-2).
8
+
5
9
  ## Installation
6
10
 
7
11
  ``` ruby
8
12
  gem 'condenser-rails'
13
+ gem 'sass-embedded' # Sass and SCSS
14
+ gem 'lightningcss', '>= 1.33.0.2' # the default CSS minifier
9
15
  ```
10
16
 
11
17
  Or alternatively `require 'condenser/railtie'` in your `config/application.rb`
12
18
  if you have Bundler auto-require disabled.
13
19
 
20
+ Sass and SCSS are compiled with [Sass Embedded](https://github.com/sass-contrib/sass-embedded-host-ruby).
21
+ CSS is minified with [Lightning CSS](https://lightningcss.dev); `lightningcss`
22
+ isn't needed if `config.assets.css_minifier` is `:sass` or `nil`.
23
+
24
+ ### JavaScript bundling
25
+
26
+ JavaScript is bundled, and minified, with [Rolldown](https://rolldown.rs) by
27
+ default. Rolldown runs in Node, so Node must be installed wherever assets are
28
+ compiled. The `rolldown` npm package is installed into the npm path
29
+ (`config.assets.npm_path`, `Rails.root` by default) the first time it's needed.
30
+
31
+ To configure Rolldown, replace the default exporter with a configured
32
+ `Condenser::RolldownProcessor` instance. Registering the class, as in earlier
33
+ versions, no longer works. Pass `minify:` yourself, since it defaults to
34
+ `false`:
35
+
36
+ ``` ruby
37
+ config.assets.configure do |app, env|
38
+ env.unregister_exporter('application/javascript', Condenser::RolldownProcessor)
39
+ env.register_exporter('application/javascript', Condenser::RolldownProcessor.new(env.npm_path,
40
+ minify: !Rails.env.local?,
41
+ aliases: { 'jquery' => app.root.join('vendor/assets/javascripts/jquery.js').to_s }
42
+ ))
43
+ end
44
+ ```
45
+
46
+ Rollup is deprecated, and will be removed in Condenser 3.
47
+ To use it instead of Rolldown:
48
+
49
+ ``` ruby
50
+ config.assets.configure do |app, env|
51
+ env.unregister_exporter('application/javascript')
52
+ env.register_exporter('application/javascript', Condenser::RollupProcessor)
53
+ end
54
+ ```
55
+
14
56
  ## Usage
15
57
 
16
58
  ### Rake task
@@ -54,15 +96,45 @@ on assets being precompiled to `public/assets` in order to link to them.
54
96
  Initializers expecting `Rails.application.assets` during boot should be accessing
55
97
  the environment in a `config.assets.configure` block. See below.
56
98
 
99
+ **`config.assets.npm_path`**
100
+
101
+ The directory npm packages, such as `rolldown`, are installed into and loaded
102
+ from. Defaults to `Rails.root`.
103
+
104
+ **`config.assets.watch`**
105
+
106
+ Directories, relative to `Rails.root` or absolute, that a running server
107
+ watches for changes to files assets depend on, without adding them to the load
108
+ path. Defaults to `['config']`; missing directories are skipped. A
109
+ `depends_on` path starting with `!` is a file relative to `Rails.root`, and
110
+ only rebuilds a running server's assets when it's under a load path or a
111
+ watched directory:
112
+
113
+ ``` js
114
+ // depends_on !config/foo.yml
115
+ const foo = <%= YAML.load_file(Rails.root.join('config/foo.yml')).to_json %>;
116
+ ```
117
+
118
+ ``` ruby
119
+ config.assets.watch << 'data'
120
+ ```
121
+
57
122
  **`config.assets.js_minifier`**
58
123
 
59
- The JS minifier to use to minify javascript sources. Default is `:terser`, valid
60
- options are `:terser`, `:uglify`, and `false` to disable minification.
124
+ The JS minifier to use to minify javascript sources. Valid options are
125
+ `:rolldown` (the default, Rolldown minifies its own output), `:terser`, your own
126
+ minifier, and `false` or `nil` to disable minification. `:terser` runs in Node,
127
+ is npm-installed into the npm path when first used, and turns Rolldown's
128
+ minifier off.
61
129
 
62
130
  **`config.assets.css_minifier`**
63
131
 
64
- The CSS minifier to use to minify css sources. Default is `:sass`, valid options
65
- are `:sass`, and `false` to disable minification.
132
+ The CSS minifier to use to minify css sources. Valid options are
133
+ `:lightning_css` (the default, which needs the `lightningcss` gem), `:sass`
134
+ (which needs the `sass-embedded` gem), your own minifier, and `false` or `nil`
135
+ to disable minification.
136
+
137
+ Assets are only minified outside the `development` and `test` environments.
66
138
 
67
139
  **`config.assets.compressors`**
68
140
 
@@ -81,8 +153,7 @@ access to the environment instance and lets you lazily load libraries only neede
81
153
  for asset compiling.
82
154
 
83
155
  ``` ruby
84
- config.assets.configure do |env|
85
-
156
+ config.assets.configure do |app, env|
86
157
  require 'my_processor'
87
158
  env.register_preprocessor 'application/javascript', MyProcessor
88
159
  end
@@ -99,9 +170,33 @@ javascript_include_tag :application, integrity: true
99
170
  # => "<script src="/assets/application.js" integrity="sha256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs="></script>"
100
171
  ```
101
172
 
102
- Note that `condenser-rails` only adds integrity hashes to assets when served in a
103
- secure context (over an HTTPS connection or localhost).
173
+ The hash is added whenever `integrity: true` is passed, over HTTP as well as
174
+ HTTPS.
175
+
176
+ ## Upgrading to Condenser 2
177
+
178
+ - Requires Condenser 2.0, Ruby 3.3 or newer, Rails 8.0 or newer, and Node
179
+ wherever assets are compiled.
180
+ - Replace `gem 'sassc'` with `gem 'sass-embedded'`, and add
181
+ `gem 'lightningcss', '>= 1.33.0.2'` unless `config.assets.css_minifier` is
182
+ `:sass` or `nil`.
183
+ - JavaScript is bundled and minified by Rolldown by default. `:uglify` is
184
+ removed; `:terser` still works, and turns Rolldown's minifier off.
185
+ - CSS is minified by Lightning CSS by default.
186
+ - A custom Rolldown exporter must be an instance:
187
+ `Condenser::RolldownProcessor.new(env.npm_path, minify: !Rails.env.local?, …)`.
188
+ - A bare `// depends_on` path that matches nothing now raises
189
+ `Condenser::FileNotFound` (globs don't). Files relative to the app root need
190
+ a `!`, e.g. `// depends_on !config/foo.yml`. `config/` is watched by default
191
+ so a running server picks up changes to them.
192
+ - A JavaScript import that can't be resolved now fails the build.
193
+ - JSON files can be imported from JavaScript, e.g. `import data from 'data.json'`.
194
+ - Sass `@use` and `@import` of npm packages pick the package's stylesheet from
195
+ its `exports` (`sass` or `style` condition), `sass` or `style` field.
196
+ - A configured `config.assets.npm_path` is now respected instead of being
197
+ reset to `Rails.root`.
198
+ - Clear `tmp/cache/assets` and `public/assets` after upgrading.
104
199
 
105
200
  ## License
106
201
 
107
- Condenser Rails is released under the [MIT License](MIT-LICENSE).
202
+ Condenser Rails is released under the [MIT License](LICENSE).
@@ -18,7 +18,7 @@ class Condenser
18
18
 
19
19
  def compute_asset_path(path, options = {})
20
20
  if asset = environment.find(path)
21
- @dependencies << asset.source_file
21
+ depend_on(asset)
22
22
  File.join(assets_prefix || "/", asset.path)
23
23
  else
24
24
  super
@@ -32,7 +32,7 @@ module Condenser::Rails
32
32
  end
33
33
 
34
34
  def self.extended(obj)
35
- obj.class_eval do
35
+ obj.singleton_class.class_eval do
36
36
  attr_accessor(*VIEW_ACCESSORS)
37
37
  end
38
38
  end
@@ -97,7 +97,7 @@ module Condenser::Rails
97
97
  else
98
98
  options["type"]
99
99
  end
100
- rel = options["type"] == "module" ? "modulepreload" : "preload"
100
+ rel = type == "module" ? "modulepreload" : "preload"
101
101
 
102
102
  if use_preload_links_header && !options["defer"] && href.present? && !href.start_with?("data:")
103
103
  preload_link = "<#{href}>; rel=#{rel}; as=script"
@@ -17,9 +17,8 @@ module Condenser::Rails
17
17
 
18
18
  def environment
19
19
  if app
20
- # Use initialized app.assets or force build an environment if
21
- # config.assets.compile is disabled
22
- app.assets || Condenser::Railtie.build_environment(app)
20
+ # Its own environment, so compiling never starts a file listener
21
+ @app_environment ||= Condenser::Railtie.build_environment(app, listen: false)
23
22
  else
24
23
  super
25
24
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Condenser
4
4
  module Rails
5
- VERSION = "1.2"
5
+ VERSION = "2.0.0.rc1"
6
6
  end
7
7
  end
@@ -43,7 +43,8 @@ module Rails
43
43
  app.config.assets.path.unshift(*paths["vendor/assets"].existent_directories)
44
44
  app.config.assets.path.unshift(*paths["lib/assets"].existent_directories)
45
45
  app.config.assets.path.unshift(*paths["app/assets"].existent_directories)
46
- app.config.assets.npm_path = app.root
46
+ # Runs after the app's config, so keep an npm_path the app set
47
+ app.config.assets.npm_path ||= app.root
47
48
  end
48
49
  end
49
50
  end
@@ -72,11 +73,19 @@ class Condenser::Railtie < ::Rails::Railtie
72
73
  config.assets.digest = true
73
74
  config.assets.cache_limit = 1_000.megabytes
74
75
  config.assets.compressors = [:zlib]
76
+ # Used outside development and test; set to nil or false to disable
77
+ config.assets.js_minifier = :rolldown
78
+ config.assets.css_minifier = :lightning_css
79
+ # Directories, relative to Rails.root or absolute, whose files can be
80
+ # `depends_on`'d and rebuild assets when they change
81
+ config.assets.watch = ['config']
75
82
 
76
83
  config.assets.configure do |app, env|
77
84
  config.assets.path.each { |path| env.append_path(path) }
78
- if config.assets.npm_path && File.directory?(config.assets.npm_path)
79
- env.append_npm_path(config.assets.npm_path)
85
+ # A no-op unless condenser is listening for changes
86
+ Array(config.assets.watch).each do |path|
87
+ path = File.expand_path(path, app.root)
88
+ env.watch(path) if File.directory?(path)
80
89
  end
81
90
  end
82
91
 
@@ -99,9 +108,14 @@ class Condenser::Railtie < ::Rails::Railtie
99
108
  Condenser::Rails::Task.new(app)
100
109
  end
101
110
 
111
+ # Minifier names that don't camelize to their class name
112
+ MINIFIERS = {
113
+ lightning_css: 'Condenser::LightningCSSMinifier'
114
+ }.freeze
115
+
102
116
  def resolve_minifier(value)
103
117
  if value.is_a?(Symbol) || value.is_a?(String)
104
- "Condenser::#{value.to_s.camelize}Minifier".constantize
118
+ (MINIFIERS[value.to_sym] || "Condenser::#{value.to_s.camelize}Minifier").constantize
105
119
  else
106
120
  value
107
121
  end
@@ -115,24 +129,35 @@ class Condenser::Railtie < ::Rails::Railtie
115
129
  end
116
130
  end
117
131
 
118
- def build_environment(app, initialized = nil)
132
+ # listen - Whether condenser watches the asset paths for changes. Default
133
+ # only in development and test.
134
+ def build_environment(app, initialized = nil, listen: ::Rails.env.local?)
119
135
  initialized = app.initialized? if initialized.nil?
120
136
  unless initialized
121
137
  ::Rails.logger.warn "Application uninitialized: Try calling YourApp::Application.initialize!"
122
138
  end
123
139
 
124
- env = Condenser.new(pipeline: false, logger: ::Rails.logger, base: app.root.to_s)
125
140
  config = app.config
126
141
 
142
+ # Set the npm path up front so exporters and custom pipelines can use it
143
+ npm_path = config.assets.npm_path if config.assets.npm_path && File.directory?(config.assets.npm_path)
144
+ env = Condenser.new(pipeline: false, logger: ::Rails.logger, base: app.root.to_s, npm_path: npm_path, listen: listen)
145
+
127
146
  if config.assets._pipeline
128
147
  config.assets._pipeline.call(env)
129
148
  else
149
+ # Only minify outside development and test
150
+ minify = !::Rails.env.local?
151
+ js_minifier = config.assets.js_minifier
152
+ # Rolldown minifies its own output unless another JS minifier is chosen
153
+ rolldown_minifies = minify && js_minifier.to_s == 'rolldown'
154
+
130
155
  env.register_transformer 'text/scss', 'text/css', Condenser::ScssTransformer.new
131
156
  env.register_preprocessor 'application/javascript', Condenser::JSAnalyzer
132
- env.register_exporter 'application/javascript', Condenser::RollupProcessor
157
+ env.register_exporter 'application/javascript', Condenser::RolldownProcessor.new(env.npm_path, minify: rolldown_minifies)
133
158
 
134
- if ::Rails.env != 'development'
135
- env.register_minifier 'application/javascript', resolve_minifier(config.assets.js_minifier) if config.assets.js_minifier
159
+ if minify
160
+ env.register_minifier 'application/javascript', resolve_minifier(js_minifier) if js_minifier && !rolldown_minifies
136
161
  env.register_minifier 'text/css', resolve_minifier(config.assets.css_minifier) if config.assets.css_minifier
137
162
  end
138
163
 
@@ -164,7 +189,7 @@ class Condenser::Railtie < ::Rails::Railtie
164
189
  app.assets = self.build_environment(app, true)
165
190
  require 'condenser/server'
166
191
  app.routes.prepend do
167
- mount Condenser::Server.new(app.assets, logger: Rails.logger) => config.assets.prefix
192
+ mount Condenser::Server.new(app.assets, logger: Rails.logger), at: config.assets.prefix
168
193
  end
169
194
  end
170
195
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: condenser-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: 2.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Bracy
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-07-22 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: condenser
@@ -16,56 +15,62 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 1.5.1
18
+ version: 2.0.0.rc1
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '3'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
26
  - - ">="
25
27
  - !ruby/object:Gem::Version
26
- version: 1.5.1
28
+ version: 2.0.0.rc1
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '3'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: actionpack
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
36
  - - ">="
32
37
  - !ruby/object:Gem::Version
33
- version: '6.0'
38
+ version: '8.0'
34
39
  type: :runtime
35
40
  prerelease: false
36
41
  version_requirements: !ruby/object:Gem::Requirement
37
42
  requirements:
38
43
  - - ">="
39
44
  - !ruby/object:Gem::Version
40
- version: '6.0'
45
+ version: '8.0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: activesupport
43
48
  requirement: !ruby/object:Gem::Requirement
44
49
  requirements:
45
50
  - - ">="
46
51
  - !ruby/object:Gem::Version
47
- version: '6.0'
52
+ version: '8.0'
48
53
  type: :runtime
49
54
  prerelease: false
50
55
  version_requirements: !ruby/object:Gem::Requirement
51
56
  requirements:
52
57
  - - ">="
53
58
  - !ruby/object:Gem::Version
54
- version: '6.0'
59
+ version: '8.0'
55
60
  - !ruby/object:Gem::Dependency
56
61
  name: railties
57
62
  requirement: !ruby/object:Gem::Requirement
58
63
  requirements:
59
64
  - - ">="
60
65
  - !ruby/object:Gem::Version
61
- version: '6.0'
66
+ version: '8.0'
62
67
  type: :development
63
68
  prerelease: false
64
69
  version_requirements: !ruby/object:Gem::Requirement
65
70
  requirements:
66
71
  - - ">="
67
72
  - !ruby/object:Gem::Version
68
- version: '6.0'
73
+ version: '8.0'
69
74
  - !ruby/object:Gem::Dependency
70
75
  name: rake
71
76
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +100,7 @@ dependencies:
95
100
  - !ruby/object:Gem::Version
96
101
  version: '0'
97
102
  - !ruby/object:Gem::Dependency
98
- name: sassc
103
+ name: sass-embedded
99
104
  requirement: !ruby/object:Gem::Requirement
100
105
  requirements:
101
106
  - - ">="
@@ -108,6 +113,20 @@ dependencies:
108
113
  - - ">="
109
114
  - !ruby/object:Gem::Version
110
115
  version: '0'
116
+ - !ruby/object:Gem::Dependency
117
+ name: lightningcss
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 1.33.0.2
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 1.33.0.2
111
130
  - !ruby/object:Gem::Dependency
112
131
  name: minitest-reporters
113
132
  requirement: !ruby/object:Gem::Requirement
@@ -122,7 +141,6 @@ dependencies:
122
141
  - - ">="
123
142
  - !ruby/object:Gem::Version
124
143
  version: '0'
125
- description:
126
144
  email: jonbracy@gmail.com
127
145
  executables: []
128
146
  extensions: []
@@ -141,7 +159,6 @@ homepage: https://github.com/malomalo/condenser-rails
141
159
  licenses:
142
160
  - MIT
143
161
  metadata: {}
144
- post_install_message:
145
162
  rdoc_options: []
146
163
  require_paths:
147
164
  - lib
@@ -149,15 +166,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
166
  requirements:
150
167
  - - ">="
151
168
  - !ruby/object:Gem::Version
152
- version: 2.5.0
169
+ version: 3.3.0
153
170
  required_rubygems_version: !ruby/object:Gem::Requirement
154
171
  requirements:
155
172
  - - ">="
156
173
  - !ruby/object:Gem::Version
157
174
  version: '0'
158
175
  requirements: []
159
- rubygems_version: 3.5.21
160
- signing_key:
176
+ rubygems_version: 4.0.11
161
177
  specification_version: 4
162
178
  summary: Condenser integration for Rails
163
179
  test_files: []