condenser-rails 0.0.9 → 1.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 +40 -49
- data/lib/condenser/rails/task.rb +4 -4
- data/lib/condenser/rails/version.rb +1 -1
- data/lib/condenser/railtie.rb +29 -49
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f89e00dbee24bef8d5da5bda26986e7df007aaa1470a2c994135fa8daa80f44
|
4
|
+
data.tar.gz: e9354937fb6f2e26a49128e81f8979a20cbfc36032efe50a92c2100b525d7197
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6b5d62420defc1458987c8320bb2b4a5b16bda531bfbdc6a9867cbdfe850432ab29376a20cdf01b546700652b2f802a9107694c30eb3763b31da334add0873c
|
7
|
+
data.tar.gz: f8a45524f97cdf97bbcdb2defae68cb7a15e48940bc19af08718146200e6f8f8a2464e96eac1287660e07b4f58a5af7fa2c336c11816fbea3f3b8a2231dbb20c
|
data/README.md
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
# Condenser Rails
|
3
2
|
|
4
3
|
Provides Condenser integration for the Rails Asset Pipeline.
|
@@ -9,107 +8,99 @@ Provides Condenser integration for the Rails Asset Pipeline.
|
|
9
8
|
gem 'condenser-rails'
|
10
9
|
```
|
11
10
|
|
12
|
-
Or alternatively `require 'condenser/railtie'` in your `config/application.rb`
|
11
|
+
Or alternatively `require 'condenser/railtie'` in your `config/application.rb`
|
12
|
+
if you have Bundler auto-require disabled.
|
13
13
|
|
14
14
|
## Usage
|
15
15
|
|
16
|
-
|
17
16
|
### Rake task
|
18
17
|
|
19
18
|
**`rake assets:precompile`**
|
20
19
|
|
21
|
-
Deployment task that compiles any assets listed in `config.assets.precompile`
|
20
|
+
Deployment task that compiles any assets listed in `config.assets.precompile`
|
21
|
+
to `public/assets`.
|
22
22
|
|
23
23
|
**`rake assets:clean`**
|
24
24
|
|
25
|
-
|
25
|
+
Removes old assets from `public/assets`. Useful when doing rolling deploys that
|
26
|
+
may still be serving old assets while the new ones are being compiled.
|
26
27
|
|
27
28
|
**`rake assets:clobber`**
|
28
29
|
|
29
30
|
Nuke `public/assets` and remove `config/manifest.json`.
|
30
31
|
|
31
|
-
|
32
|
+
### Initializer options
|
32
33
|
|
33
|
-
|
34
|
+
**`config.assets.precompile`**
|
34
35
|
|
35
|
-
|
36
|
+
Add additional assets to compile on deploy. Defaults to `application.js`,
|
37
|
+
`application.css` and any `.jpg`, `.png`, or `.gif` files under `app/assets`.
|
36
38
|
|
37
|
-
|
38
|
-
require 'condenser/rails/task'
|
39
|
-
Condenser::Rails::Task.new(Rails.application) do |t|
|
40
|
-
t.environment = lambda { Rails.application.assets }
|
41
|
-
t.assets = %w( application.js application.css )
|
42
|
-
t.keep = 5
|
43
|
-
end
|
44
|
-
```
|
39
|
+
**`config.assets.path`**
|
45
40
|
|
46
|
-
|
41
|
+
Add additional load paths to this Array. Rails includes `app/assets`,
|
42
|
+
`lib/assets` and `vendor/assets` for you already. Plugins might want to add
|
43
|
+
their custom paths to this.
|
47
44
|
|
48
|
-
|
45
|
+
**`config.assets.prefix`**
|
49
46
|
|
50
|
-
|
47
|
+
Defaults to `/assets`. Changes the directory to compile assets to.
|
51
48
|
|
52
|
-
**`config.assets.
|
49
|
+
**`config.assets.compile`**
|
53
50
|
|
54
|
-
|
51
|
+
Enables the Condenser compile environment. If disabled, `Rails.application.assets`
|
52
|
+
will be `nil` to prevent inadvertent compilation calls. View helpers will depend
|
53
|
+
on assets being precompiled to `public/assets` in order to link to them.
|
54
|
+
Initializers expecting `Rails.application.assets` during boot should be accessing
|
55
|
+
the environment in a `config.assets.configure` block. See below.
|
55
56
|
|
56
|
-
**`config.assets.
|
57
|
+
**`config.assets.js_minifier`**
|
57
58
|
|
58
|
-
|
59
|
+
The JS minifier to use to minify javascript sources. Default is `:terser`, valid
|
60
|
+
options are `:terser`, `:uglify`, and `false` to disable minification.
|
59
61
|
|
60
|
-
**`config.assets.
|
62
|
+
**`config.assets.css_minifier`**
|
61
63
|
|
62
|
-
|
64
|
+
The CSS minifier to use to minify css sources. Default is `:sass`, valid options
|
65
|
+
are `:sass`, and `false` to disable minification.
|
63
66
|
|
64
|
-
**`config.assets.
|
67
|
+
**`config.assets.compressors`**
|
65
68
|
|
66
|
-
|
69
|
+
A list of compressors to compress the output with. Each file will be written along
|
70
|
+
with a compressed version for each compressor. Default is `[:zlib]` which will
|
71
|
+
add a `.gz` version of each file. Valid options are `:zlib`, and `:brotli`. To
|
72
|
+
disable set this to an empty array or `false`.
|
67
73
|
|
68
|
-
|
74
|
+
Optionally you may also set this to your own compressor.
|
69
75
|
|
70
|
-
Enables the Condenser compile environment. If disabled, `Rails.application.assets` will be `nil` to prevent inadvertent compilation calls. View helpers will depend on assets being precompiled to `public/assets` in order to link to them. Initializers expecting `Rails.application.assets` during boot should be accessing the environment in a `config.assets.configure` block. See below.
|
71
76
|
|
72
77
|
**`config.assets.configure`**
|
73
78
|
|
74
|
-
Invokes block with environment when the environment is initialized. Allows direct
|
79
|
+
Invokes block with environment when the environment is initialized. Allows direct
|
80
|
+
access to the environment instance and lets you lazily load libraries only needed
|
81
|
+
for asset compiling.
|
75
82
|
|
76
83
|
``` ruby
|
77
84
|
config.assets.configure do |env|
|
78
|
-
env.js_compressor = :uglifier
|
79
|
-
env.css_compressor = :sass
|
80
85
|
|
81
86
|
require 'my_processor'
|
82
87
|
env.register_preprocessor 'application/javascript', MyProcessor
|
83
|
-
|
84
|
-
env.logger = Rails.logger
|
85
88
|
end
|
86
89
|
```
|
87
90
|
|
88
|
-
**`config.assets.check_precompiled_asset`**
|
89
|
-
|
90
|
-
When enabled, an exception is raised for missing assets. This option is enabled by default.
|
91
|
-
|
92
|
-
## Complementary plugins
|
93
|
-
|
94
|
-
The following plugins provide some extras for the Sprockets Asset Pipeline.
|
95
|
-
|
96
|
-
* [sass-rails](https://github.com/rails/sass-rails)
|
97
|
-
|
98
|
-
**NOTE** That these plugins are optional. The core coffee-script, sass, less, uglify, (and many more) features are built into Sprockets itself. Many of these plugins only provide generators and extra helpers. You can probably get by without them.
|
99
|
-
|
100
|
-
|
101
91
|
## Other
|
102
92
|
|
103
93
|
### [SRI](http://www.w3.org/TR/SRI/) support
|
104
94
|
|
105
|
-
Condenser adds support for subresource integrity checks.
|
95
|
+
Condenser adds support for subresource integrity checks.
|
106
96
|
|
107
97
|
``` ruby
|
108
98
|
javascript_include_tag :application, integrity: true
|
109
99
|
# => "<script src="/assets/application.js" integrity="sha256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs="></script>"
|
110
100
|
```
|
111
101
|
|
112
|
-
Note that condenser-rails only adds integrity hashes to assets when served in a
|
102
|
+
Note that `condenser-rails` only adds integrity hashes to assets when served in a
|
103
|
+
secure context (over an HTTPS connection or localhost).
|
113
104
|
|
114
105
|
## License
|
115
106
|
|
data/lib/condenser/rails/task.rb
CHANGED
@@ -62,21 +62,21 @@ module Condenser::Rails
|
|
62
62
|
end
|
63
63
|
|
64
64
|
desc "Compile all the assets named in config.assets.precompile"
|
65
|
-
task :
|
65
|
+
task precompile: :environment do
|
66
66
|
with_logger do
|
67
67
|
manifest.compile(assets)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
desc "Remove old compiled assets"
|
72
|
-
task
|
72
|
+
task clean: :environment do
|
73
73
|
with_logger do
|
74
|
-
manifest.clean
|
74
|
+
manifest.clean
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
desc "Remove compiled assets"
|
79
|
-
task :
|
79
|
+
task clobber: :environment do
|
80
80
|
with_logger do
|
81
81
|
manifest.clobber
|
82
82
|
end
|
data/lib/condenser/railtie.rb
CHANGED
@@ -8,8 +8,6 @@ require 'condenser/rails/utils'
|
|
8
8
|
require 'condenser/rails/context'
|
9
9
|
require 'condenser/rails/helper'
|
10
10
|
require 'condenser/rails/version'
|
11
|
-
# require 'sprockets/rails/quiet_assets'
|
12
|
-
# require 'sprockets/rails/route_wrapper'
|
13
11
|
|
14
12
|
module Rails
|
15
13
|
class Application
|
@@ -43,7 +41,7 @@ module Rails
|
|
43
41
|
app.config.assets.path.unshift(*paths["vendor/assets"].existent_directories)
|
44
42
|
app.config.assets.path.unshift(*paths["lib/assets"].existent_directories)
|
45
43
|
app.config.assets.path.unshift(*paths["app/assets"].existent_directories)
|
46
|
-
app.config.assets.npm_path = app.root
|
44
|
+
app.config.assets.npm_path = app.root
|
47
45
|
end
|
48
46
|
end
|
49
47
|
end
|
@@ -54,6 +52,10 @@ class Condenser::Railtie < ::Rails::Railtie
|
|
54
52
|
def configure(&block)
|
55
53
|
self._blocks << block
|
56
54
|
end
|
55
|
+
|
56
|
+
def pipeline(&block)
|
57
|
+
self._pipeline = block
|
58
|
+
end
|
57
59
|
end
|
58
60
|
|
59
61
|
module SassFunctions
|
@@ -67,16 +69,8 @@ class Condenser::Railtie < ::Rails::Railtie
|
|
67
69
|
config.assets.path = []
|
68
70
|
config.assets.precompile = %w(application.css application.js **/*.jpg **/*.png **/*.gif)
|
69
71
|
config.assets.prefix = "/assets"
|
70
|
-
config.assets.quiet = false
|
71
72
|
config.assets.manifest = 'config/manifest.json'
|
72
73
|
|
73
|
-
# initializer :quiet_assets do |app|
|
74
|
-
# if app.config.assets.quiet
|
75
|
-
# app.middleware.insert_before ::Rails::Rack::Logger, ::Condenser::Rails::QuietAssets
|
76
|
-
# end
|
77
|
-
# end
|
78
|
-
|
79
|
-
# config.assets.version = ""
|
80
74
|
config.assets.compile = true
|
81
75
|
config.assets.digest = true
|
82
76
|
config.assets.cache_limit = 100.megabytes
|
@@ -103,18 +97,6 @@ class Condenser::Railtie < ::Rails::Railtie
|
|
103
97
|
)
|
104
98
|
end
|
105
99
|
|
106
|
-
# Sprockets.register_dependency_resolver 'rails-env' do
|
107
|
-
# ::Rails.env.to_s
|
108
|
-
# end
|
109
|
-
|
110
|
-
# config.assets.configure do |env|
|
111
|
-
# env.depend_on 'rails-env'
|
112
|
-
# end
|
113
|
-
|
114
|
-
# config.assets.configure do |app, env|
|
115
|
-
# env.version = config.assets.version
|
116
|
-
# end
|
117
|
-
|
118
100
|
rake_tasks do |app|
|
119
101
|
require 'condenser/rails/task'
|
120
102
|
Condenser::Rails::Task.new(app)
|
@@ -145,37 +127,35 @@ class Condenser::Railtie < ::Rails::Railtie
|
|
145
127
|
env = Condenser.new(pipeline: false, logger: ::Rails.logger)
|
146
128
|
config = app.config
|
147
129
|
|
148
|
-
|
149
|
-
config.assets._blocks.each do |block|
|
150
|
-
block.call(app, env)
|
151
|
-
end
|
130
|
+
if config.assets._pipeline
|
152
131
|
|
153
|
-
env.register_transformer 'text/scss', 'text/css', Condenser::ScssTransformer.new({
|
154
|
-
functions: Condenser::Railtie::SassFunctions
|
155
|
-
})
|
156
|
-
|
157
|
-
# Set compressors after the configure blocks since they can
|
158
|
-
# define new compressors and we only accept existent compressors.
|
159
|
-
if ::Rails.env == 'development'
|
160
|
-
env.register_preprocessor 'application/javascript', Condenser::BabelProcessor.new({
|
161
|
-
plugins: [
|
162
|
-
["#{Condenser::BabelProcessor.node_modules_path}/babel-plugin-transform-class-extended-hook", {}],
|
163
|
-
["#{Condenser::BabelProcessor.node_modules_path}/@babel/plugin-proposal-class-properties", {}]
|
164
|
-
],
|
165
|
-
presets: nil
|
166
|
-
})
|
167
132
|
else
|
168
|
-
env.
|
169
|
-
|
133
|
+
env.register_transformer 'text/scss', 'text/css', Condenser::ScssTransformer.new({
|
134
|
+
functions: Condenser::Railtie::SassFunctions
|
135
|
+
})
|
136
|
+
|
137
|
+
if ::Rails.env == 'development'
|
138
|
+
env.register_preprocessor 'application/javascript', Condenser::JSAnalyzer
|
139
|
+
else
|
140
|
+
env.register_preprocessor 'application/javascript', Condenser::BabelProcessor
|
141
|
+
end
|
170
142
|
|
171
|
-
|
143
|
+
env.register_exporter 'application/javascript', Condenser::RollupProcessor
|
144
|
+
|
145
|
+
if ::Rails.env != 'development'
|
146
|
+
env.register_minifier 'application/javascript', resolve_minifier(config.assets.js_minifier) if config.assets.js_minifier
|
147
|
+
env.register_minifier 'text/css', resolve_minifier(config.assets.css_minifier) if config.assets.css_minifier
|
148
|
+
end
|
172
149
|
|
173
|
-
|
174
|
-
|
150
|
+
env.register_writer Condenser::FileWriter.new
|
151
|
+
config.assets.compressors&.each do |writer|
|
152
|
+
env.register_writer resolve_writer(writer)
|
153
|
+
end
|
154
|
+
end
|
175
155
|
|
176
|
-
|
177
|
-
config.assets.
|
178
|
-
|
156
|
+
# Run app.assets.configure blocks
|
157
|
+
config.assets._blocks.each do |block|
|
158
|
+
block.call(app, env)
|
179
159
|
end
|
180
160
|
|
181
161
|
env
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: condenser-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: condenser
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.0.rc1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.0.rc1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionpack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,11 +166,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
166
|
version: 2.5.0
|
167
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
168
|
requirements:
|
169
|
-
- - "
|
169
|
+
- - ">"
|
170
170
|
- !ruby/object:Gem::Version
|
171
|
-
version:
|
171
|
+
version: 1.3.1
|
172
172
|
requirements: []
|
173
|
-
rubygems_version: 3.
|
173
|
+
rubygems_version: 3.0.6
|
174
174
|
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: Condenser integration for Rails
|