condenser-rails 1.1 → 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 +4 -4
- data/README.md +104 -9
- data/lib/condenser/rails/context.rb +3 -1
- data/lib/condenser/rails/helper.rb +91 -42
- data/lib/condenser/rails/task.rb +4 -3
- data/lib/condenser/rails/utils.rb +2 -0
- data/lib/condenser/rails/version.rb +3 -1
- data/lib/condenser/rails.rb +2 -0
- data/lib/condenser/railtie.rb +39 -18
- metadata +33 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af5ea6490579f3e2d0ad960b7b105ead8d9e65841d5c3554275f77593d9dea40
|
|
4
|
+
data.tar.gz: 6b3be923f9411e60fa19c16e4e9087210d8251247066e7b560dc8c6f8406ea58
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
60
|
-
|
|
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.
|
|
65
|
-
|
|
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
|
-
|
|
103
|
-
|
|
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](
|
|
202
|
+
Condenser Rails is released under the [MIT License](LICENSE).
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'action_view/helpers'
|
|
2
4
|
require 'condenser'
|
|
3
5
|
|
|
@@ -16,7 +18,7 @@ class Condenser
|
|
|
16
18
|
|
|
17
19
|
def compute_asset_path(path, options = {})
|
|
18
20
|
if asset = environment.find(path)
|
|
19
|
-
|
|
21
|
+
depend_on(asset)
|
|
20
22
|
File.join(assets_prefix || "/", asset.path)
|
|
21
23
|
else
|
|
22
24
|
super
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'action_view'
|
|
2
4
|
require 'condenser'
|
|
3
5
|
require 'active_support/core_ext/class/attribute'
|
|
@@ -30,7 +32,7 @@ module Condenser::Rails
|
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
def self.extended(obj)
|
|
33
|
-
obj.class_eval do
|
|
35
|
+
obj.singleton_class.class_eval do
|
|
34
36
|
attr_accessor(*VIEW_ACCESSORS)
|
|
35
37
|
end
|
|
36
38
|
end
|
|
@@ -61,75 +63,115 @@ module Condenser::Rails
|
|
|
61
63
|
def asset_integrity(path, options = {})
|
|
62
64
|
asset_resolver.integrity(path)
|
|
63
65
|
end
|
|
64
|
-
|
|
65
|
-
#
|
|
66
|
+
|
|
67
|
+
# Get type for asset path. (module or nil for javascript)
|
|
68
|
+
#
|
|
69
|
+
# path - String path
|
|
70
|
+
# options - Hash options
|
|
66
71
|
#
|
|
67
|
-
#
|
|
72
|
+
# Returns String integrity attribute or nil if no asset was found.
|
|
73
|
+
def asset_type(path, options = {})
|
|
74
|
+
asset_resolver.type(path)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# TODO: perhaps prepend this function and add integrity if set to true?
|
|
68
78
|
def javascript_include_tag(*sources)
|
|
69
79
|
options = sources.extract_options!.stringify_keys
|
|
70
80
|
path_options = options.extract!("protocol", "extname", "host", "skip_pipeline").symbolize_keys
|
|
71
|
-
|
|
81
|
+
preload_links = []
|
|
82
|
+
use_preload_links_header = options["preload_links_header"].nil? ? preload_links_header : options.delete("preload_links_header")
|
|
83
|
+
nopush = options["nopush"].nil? ? true : options.delete("nopush")
|
|
84
|
+
crossorigin = options.delete("crossorigin")
|
|
85
|
+
crossorigin = "anonymous" if crossorigin == true
|
|
86
|
+
integrity = options["integrity"]
|
|
72
87
|
|
|
73
88
|
sources_tags = sources.uniq.map { |source|
|
|
74
89
|
href = path_to_javascript(source, path_options)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
90
|
+
integrity = if options["integrity"] == true
|
|
91
|
+
asset_integrity(source.to_s.delete_suffix('.js')+'.js')
|
|
92
|
+
elsif options["integrity"] != false
|
|
93
|
+
options["integrity"]
|
|
94
|
+
end
|
|
95
|
+
type = if !options.has_key?('type')
|
|
96
|
+
asset_type(source.to_s.delete_suffix('.js')+'.js')
|
|
97
|
+
else
|
|
98
|
+
options["type"]
|
|
99
|
+
end
|
|
100
|
+
rel = type == "module" ? "modulepreload" : "preload"
|
|
79
101
|
|
|
102
|
+
if use_preload_links_header && !options["defer"] && href.present? && !href.start_with?("data:")
|
|
103
|
+
preload_link = "<#{href}>; rel=#{rel}; as=script"
|
|
104
|
+
preload_link += "; crossorigin=#{crossorigin}" unless crossorigin.nil?
|
|
105
|
+
preload_link += "; integrity=#{integrity}" unless integrity.nil?
|
|
106
|
+
preload_link += "; nonce=#{content_security_policy_nonce}" if options["nonce"] == true
|
|
107
|
+
preload_link += "; nopush" if nopush
|
|
108
|
+
preload_links << preload_link
|
|
109
|
+
end
|
|
110
|
+
tag_options = {
|
|
111
|
+
"src" => href,
|
|
112
|
+
"crossorigin" => crossorigin
|
|
113
|
+
}.merge!(options.except('integrity', 'type'))
|
|
80
114
|
if tag_options["nonce"] == true
|
|
81
115
|
tag_options["nonce"] = content_security_policy_nonce
|
|
82
116
|
end
|
|
83
|
-
|
|
84
|
-
if
|
|
85
|
-
if tag_options["integrity"] == true
|
|
86
|
-
tag_options["integrity"] = asset_integrity(source.to_s.delete_suffix('.js')+'.js')
|
|
87
|
-
elsif tag_options["integrity"] == false
|
|
88
|
-
tag_options.delete('integrity')
|
|
89
|
-
end
|
|
90
|
-
else
|
|
91
|
-
tag_options.delete('integrity')
|
|
92
|
-
end
|
|
117
|
+
tag_options['type'] = type if type
|
|
118
|
+
tag_options['integrity'] = integrity if integrity
|
|
93
119
|
|
|
94
120
|
content_tag("script", "", tag_options)
|
|
95
121
|
}.join("\n").html_safe
|
|
96
122
|
|
|
97
|
-
|
|
123
|
+
if use_preload_links_header
|
|
124
|
+
send_preload_links_header(preload_links)
|
|
125
|
+
end
|
|
98
126
|
|
|
99
127
|
sources_tags
|
|
100
128
|
end
|
|
101
129
|
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
# Eventually will be deprecated and replaced by source maps.
|
|
130
|
+
# TODO: perhaps prepend this function and add integrity if set to true?
|
|
105
131
|
def stylesheet_link_tag(*sources)
|
|
106
132
|
options = sources.extract_options!.stringify_keys
|
|
107
|
-
path_options = options.extract!("protocol", "host", "skip_pipeline").symbolize_keys
|
|
108
|
-
|
|
109
|
-
|
|
133
|
+
path_options = options.extract!("protocol", "extname", "host", "skip_pipeline").symbolize_keys
|
|
134
|
+
use_preload_links_header = options["preload_links_header"].nil? ? preload_links_header : options.delete("preload_links_header")
|
|
135
|
+
preload_links = []
|
|
136
|
+
crossorigin = options.delete("crossorigin")
|
|
137
|
+
crossorigin = "anonymous" if crossorigin == true
|
|
138
|
+
nopush = options["nopush"].nil? ? true : options.delete("nopush")
|
|
139
|
+
|
|
110
140
|
sources_tags = sources.uniq.map { |source|
|
|
111
141
|
href = path_to_stylesheet(source, path_options)
|
|
112
|
-
|
|
142
|
+
integrity = if options["integrity"] == true
|
|
143
|
+
asset_integrity(source.to_s.delete_suffix('.css')+'.css')
|
|
144
|
+
elsif options["integrity"] != false
|
|
145
|
+
options["integrity"]
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
if use_preload_links_header && href.present? && !href.start_with?("data:")
|
|
149
|
+
preload_link = "<#{href}>; rel=preload; as=style"
|
|
150
|
+
preload_link += "; crossorigin=#{crossorigin}" unless crossorigin.nil?
|
|
151
|
+
preload_link += "; integrity=#{integrity}" unless integrity.nil?
|
|
152
|
+
preload_link += "; nopush" if nopush
|
|
153
|
+
preload_links << preload_link
|
|
154
|
+
end
|
|
113
155
|
tag_options = {
|
|
114
156
|
"rel" => "stylesheet",
|
|
115
|
-
"
|
|
157
|
+
"crossorigin" => crossorigin,
|
|
116
158
|
"href" => href
|
|
117
|
-
}.merge!(options)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if tag_options["integrity"] == true
|
|
121
|
-
tag_options["integrity"] = asset_integrity(source.to_s.delete_suffix('.css')+'.css')
|
|
122
|
-
elsif tag_options["integrity"] == false
|
|
123
|
-
tag_options.delete('integrity')
|
|
124
|
-
end
|
|
125
|
-
else
|
|
126
|
-
tag_options.delete('integrity')
|
|
159
|
+
}.merge!(options.except('integrity'))
|
|
160
|
+
if tag_options["nonce"] == true
|
|
161
|
+
tag_options["nonce"] = content_security_policy_nonce
|
|
127
162
|
end
|
|
163
|
+
tag_options['integrity'] = integrity if integrity
|
|
128
164
|
|
|
165
|
+
if apply_stylesheet_media_default && tag_options["media"].blank?
|
|
166
|
+
tag_options["media"] = "screen"
|
|
167
|
+
end
|
|
168
|
+
|
|
129
169
|
tag(:link, tag_options)
|
|
130
170
|
}.join("\n").html_safe
|
|
131
171
|
|
|
132
|
-
|
|
172
|
+
if use_preload_links_header
|
|
173
|
+
send_preload_links_header(preload_links)
|
|
174
|
+
end
|
|
133
175
|
|
|
134
176
|
sources_tags
|
|
135
177
|
end
|
|
@@ -175,13 +217,16 @@ module Condenser::Rails
|
|
|
175
217
|
end
|
|
176
218
|
|
|
177
219
|
def asset_path(path)
|
|
178
|
-
@manifest[path][
|
|
220
|
+
@manifest[path][:path]
|
|
179
221
|
end
|
|
180
222
|
|
|
181
223
|
def integrity(path)
|
|
182
|
-
@manifest[path][
|
|
224
|
+
@manifest[path]&.[](:integrity)
|
|
183
225
|
end
|
|
184
226
|
|
|
227
|
+
def type(path)
|
|
228
|
+
@manifest[path]&.[](:type)
|
|
229
|
+
end
|
|
185
230
|
end
|
|
186
231
|
|
|
187
232
|
class Environment #:nodoc:
|
|
@@ -201,7 +246,11 @@ module Condenser::Rails
|
|
|
201
246
|
end
|
|
202
247
|
|
|
203
248
|
def integrity(path)
|
|
204
|
-
@env.find(path)&.integrity
|
|
249
|
+
@env.find(path)&.export&.integrity
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def type(path)
|
|
253
|
+
@env.find(path)&.export&.type
|
|
205
254
|
end
|
|
206
255
|
|
|
207
256
|
private
|
data/lib/condenser/rails/task.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rake'
|
|
2
4
|
require 'rake/condensertask'
|
|
3
5
|
require 'condenser'
|
|
@@ -15,9 +17,8 @@ module Condenser::Rails
|
|
|
15
17
|
|
|
16
18
|
def environment
|
|
17
19
|
if app
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
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)
|
|
21
22
|
else
|
|
22
23
|
super
|
|
23
24
|
end
|
data/lib/condenser/rails.rb
CHANGED
data/lib/condenser/railtie.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rails'
|
|
2
4
|
require 'rails/railtie'
|
|
3
5
|
require 'action_controller/railtie'
|
|
@@ -41,7 +43,8 @@ module Rails
|
|
|
41
43
|
app.config.assets.path.unshift(*paths["vendor/assets"].existent_directories)
|
|
42
44
|
app.config.assets.path.unshift(*paths["lib/assets"].existent_directories)
|
|
43
45
|
app.config.assets.path.unshift(*paths["app/assets"].existent_directories)
|
|
44
|
-
app
|
|
46
|
+
# Runs after the app's config, so keep an npm_path the app set
|
|
47
|
+
app.config.assets.npm_path ||= app.root
|
|
45
48
|
end
|
|
46
49
|
end
|
|
47
50
|
end
|
|
@@ -68,13 +71,21 @@ class Condenser::Railtie < ::Rails::Railtie
|
|
|
68
71
|
|
|
69
72
|
config.assets.compile = true
|
|
70
73
|
config.assets.digest = true
|
|
71
|
-
config.assets.cache_limit =
|
|
74
|
+
config.assets.cache_limit = 1_000.megabytes
|
|
72
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']
|
|
73
82
|
|
|
74
83
|
config.assets.configure do |app, env|
|
|
75
84
|
config.assets.path.each { |path| env.append_path(path) }
|
|
76
|
-
|
|
77
|
-
|
|
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)
|
|
78
89
|
end
|
|
79
90
|
end
|
|
80
91
|
|
|
@@ -97,9 +108,14 @@ class Condenser::Railtie < ::Rails::Railtie
|
|
|
97
108
|
Condenser::Rails::Task.new(app)
|
|
98
109
|
end
|
|
99
110
|
|
|
111
|
+
# Minifier names that don't camelize to their class name
|
|
112
|
+
MINIFIERS = {
|
|
113
|
+
lightning_css: 'Condenser::LightningCSSMinifier'
|
|
114
|
+
}.freeze
|
|
115
|
+
|
|
100
116
|
def resolve_minifier(value)
|
|
101
117
|
if value.is_a?(Symbol) || value.is_a?(String)
|
|
102
|
-
"Condenser::#{value.to_s.camelize}Minifier".constantize
|
|
118
|
+
(MINIFIERS[value.to_sym] || "Condenser::#{value.to_s.camelize}Minifier").constantize
|
|
103
119
|
else
|
|
104
120
|
value
|
|
105
121
|
end
|
|
@@ -113,30 +129,35 @@ class Condenser::Railtie < ::Rails::Railtie
|
|
|
113
129
|
end
|
|
114
130
|
end
|
|
115
131
|
|
|
116
|
-
|
|
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?)
|
|
117
135
|
initialized = app.initialized? if initialized.nil?
|
|
118
136
|
unless initialized
|
|
119
137
|
::Rails.logger.warn "Application uninitialized: Try calling YourApp::Application.initialize!"
|
|
120
138
|
end
|
|
121
139
|
|
|
122
|
-
env = Condenser.new(pipeline: false, logger: ::Rails.logger, base: app.root.to_s)
|
|
123
140
|
config = app.config
|
|
124
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
|
+
|
|
125
146
|
if config.assets._pipeline
|
|
126
147
|
config.assets._pipeline.call(env)
|
|
127
148
|
else
|
|
128
|
-
|
|
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'
|
|
129
154
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
env.register_preprocessor 'application/javascript', Condenser::BabelProcessor
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
env.register_exporter 'application/javascript', Condenser::RollupProcessor
|
|
155
|
+
env.register_transformer 'text/scss', 'text/css', Condenser::ScssTransformer.new
|
|
156
|
+
env.register_preprocessor 'application/javascript', Condenser::JSAnalyzer
|
|
157
|
+
env.register_exporter 'application/javascript', Condenser::RolldownProcessor.new(env.npm_path, minify: rolldown_minifies)
|
|
137
158
|
|
|
138
|
-
if
|
|
139
|
-
env.register_minifier 'application/javascript', resolve_minifier(
|
|
159
|
+
if minify
|
|
160
|
+
env.register_minifier 'application/javascript', resolve_minifier(js_minifier) if js_minifier && !rolldown_minifies
|
|
140
161
|
env.register_minifier 'text/css', resolve_minifier(config.assets.css_minifier) if config.assets.css_minifier
|
|
141
162
|
end
|
|
142
163
|
|
|
@@ -168,7 +189,7 @@ class Condenser::Railtie < ::Rails::Railtie
|
|
|
168
189
|
app.assets = self.build_environment(app, true)
|
|
169
190
|
require 'condenser/server'
|
|
170
191
|
app.routes.prepend do
|
|
171
|
-
mount Condenser::Server.new(app.assets, logger: Rails.logger)
|
|
192
|
+
mount Condenser::Server.new(app.assets, logger: Rails.logger), at: config.assets.prefix
|
|
172
193
|
end
|
|
173
194
|
end
|
|
174
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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:
|
|
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:
|
|
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:
|
|
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: []
|