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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbcf380120b7098587a900eb941ae4191fa43f7d9f8e5a09ac497a43dc4f32f1
4
- data.tar.gz: cfcc292898bf9dda83d508edb9c9d9635383ece874ac153057b7bb8aa5fb27a9
3
+ metadata.gz: 5f89e00dbee24bef8d5da5bda26986e7df007aaa1470a2c994135fa8daa80f44
4
+ data.tar.gz: e9354937fb6f2e26a49128e81f8979a20cbfc36032efe50a92c2100b525d7197
5
5
  SHA512:
6
- metadata.gz: 5c529f830ad5484b9df6a0f0c9ea588abf1dbfe983a2de98d171c5c1d35e20821133f18963cbfee47336f7f01133a68e9c32ece8a87afcc1fce83be2717f2339
7
- data.tar.gz: 227f34f7567f6473c19a75f5616d343e56502d10e502247e74da246c892b36ab6cacd99e040e7f567107adc6125685968b2da5d3f6cffe4f518577a8dbc59455
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` if you have Bundler auto-require disabled.
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` to `public/assets`.
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
- Only removes old assets (keeps the most recent 3 copies) from `public/assets`. Useful when doing rolling deploys that may still be serving old assets while the new ones are being compiled.
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
- #### Customize
32
+ ### Initializer options
32
33
 
33
- If the basic tasks don't do all that you need, it's straight forward to redefine them and replace them with something more specific to your app.
34
+ **`config.assets.precompile`**
34
35
 
35
- You can also redefine the task with the built in task generator.
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
- ``` ruby
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
- Each asset task will invoke `assets:environment` first. By default this loads the Rails environment. You can override this task to add or remove dependencies for your specific compilation environment.
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
- Also see [Condenser::Rails::Task](https://github.com/rails/condenser-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::CondenserTask](https://github.com/rails/condenser/blob/master/lib/rake/condensertask.rb).
45
+ **`config.assets.prefix`**
49
46
 
50
- ### Initializer options
47
+ Defaults to `/assets`. Changes the directory to compile assets to.
51
48
 
52
- **`config.assets.precompile`**
49
+ **`config.assets.compile`**
53
50
 
54
- Add additional assets to compile on deploy. Defaults to `application.js`, `application.css` and any `.jpg`, `.png`, or `.gif` files under `app/assets`.
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.path`**
57
+ **`config.assets.js_minifier`**
57
58
 
58
- Add additional load paths to this Array. Rails includes `app/assets`, `lib/assets` and `vendor/assets` for you already. Plugins might want to add their custom paths to this.
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.quiet`**
62
+ **`config.assets.css_minifier`**
61
63
 
62
- Suppresses logger output for asset requests. Uses the `config.assets.prefix` path to match asset requests. Defaults to `false`.
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.prefix`**
67
+ **`config.assets.compressors`**
65
68
 
66
- Defaults to `/assets`. Changes the directory to compile assets to.
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
- **`config.assets.compile`**
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 access to the environment instance and lets you lazily load libraries only needed for asset compiling.
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. The spec is still evolving and the API may change in backwards incompatible ways.
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 secure context (over an HTTPS connection or localhost).
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
 
@@ -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 :precompile => :environment do
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 :clean, [:keep] => :environment do |t, args|
72
+ task clean: :environment do
73
73
  with_logger do
74
- manifest.clean #Integer(args.keep || self.keep)
74
+ manifest.clean
75
75
  end
76
76
  end
77
77
 
78
78
  desc "Remove compiled assets"
79
- task :clobber => :environment do
79
+ task clobber: :environment do
80
80
  with_logger do
81
81
  manifest.clobber
82
82
  end
@@ -1,5 +1,5 @@
1
1
  class Condenser
2
2
  module Rails
3
- VERSION = "0.0.9"
3
+ VERSION = "1.0.rc1"
4
4
  end
5
5
  end
@@ -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.join('node_modules').to_s
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
- # Run app.assets.configure blocks
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.register_preprocessor 'application/javascript', Condenser::BabelProcessor.new()
169
- end
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
- env.register_exporter 'application/javascript', Condenser::RollupProcessor
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
- env.register_minifier 'application/javascript', resolve_minifier(config.assets.js_minifier) if config.assets.js_minifier
174
- env.register_minifier 'text/css', resolve_minifier(config.assets.css_minifier) if config.assets.css_minifier
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
- env.register_writer Condenser::FileWriter.new
177
- config.assets.compressors&.each do |writer|
178
- env.register_writer resolve_writer(writer)
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: 0.0.9
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-09 00:00:00.000000000 Z
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: 0.0.7
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: 0.0.7
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: '0'
171
+ version: 1.3.1
172
172
  requirements: []
173
- rubygems_version: 3.1.2
173
+ rubygems_version: 3.0.6
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: Condenser integration for Rails