assets-minify-rails 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +40 -0
- data/lib/assets/minify/compressor.rb +34 -0
- data/lib/assets/minify/errors.rb +5 -0
- data/lib/assets/minify/output_path.rb +13 -0
- data/lib/assets/minify/railtie.rb +13 -0
- data/lib/assets/minify/version.rb +7 -0
- data/lib/assets-minify-rails.rb +11 -0
- data/lib/tasks/assets/minify/compress.rake +30 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0916dc0174afd48a4a309e2287726fddaf8f16f814236544c84e1ccc4ae21bba'
|
4
|
+
data.tar.gz: da479e9c1da1ebe872fda191fda2f71d986a0c91bf559fd923394f2d7eeedccd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 14246a81f887d6574c49030498998b11b53bb227e21f3391e046ea16fa566e1de0fab43f25fa6850367b832a830a637b7f6ad16c31d5828af47d5af6571738ba
|
7
|
+
data.tar.gz: 3adb31390282082962e2bfe1d197aa3ebe51d7adffa2ca0d1981af8e7c00b74836a01081a0a10346a66153a7801e3b4e8c5da99ce7f1f4452e567feca7185bd1
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Assets::Minify::Rails
|
2
|
+
|
3
|
+
![release](https://img.shields.io/github/v/release/newsdict/assets-minify-rails)
|
4
|
+
![license](https://img.shields.io/github/license/newsdict/assets-minify-rails)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'assets-minify-rails'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install asset-minify-rails
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
When you do asset:precompile, minify runs automatically. Note that this will overwrite the existing path. The following tasks can also be done independently.
|
25
|
+
|
26
|
+
```
|
27
|
+
$ rails assets_minify:compress
|
28
|
+
```
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
This gem minifies js, css files under Rails.application.config.output_path with yui or terser.
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/newsdict/assets-minify-rails.
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Assets::Minify
|
4
|
+
class Compressor
|
5
|
+
def initialize(file_path)
|
6
|
+
@config = ::Rails.application.config
|
7
|
+
@file_path = file_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def js_compress
|
11
|
+
case js_compressor
|
12
|
+
when :yui, :yui_compressor
|
13
|
+
::YUI::JavaScriptCompressor.new.compress(File.read(@file_path))
|
14
|
+
when :terser
|
15
|
+
::Terser.compile(File.read(@file_path))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def css_compress
|
20
|
+
case css_compressor
|
21
|
+
when :yui, :yui_compressor
|
22
|
+
::YUI::CssCompressor.new.compress(File.read(@file_path))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def js_compressor
|
27
|
+
@config.js_compressor
|
28
|
+
end
|
29
|
+
|
30
|
+
def css_compressor
|
31
|
+
@config.css_compressor
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Assets::Minify
|
4
|
+
class OutputPath
|
5
|
+
def initialize(path)
|
6
|
+
@path = path
|
7
|
+
end
|
8
|
+
|
9
|
+
def files(child = nil)
|
10
|
+
(child || @path).children.flat_map { |child| child.directory? ? files(child) : child }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Assets::Minify
|
4
|
+
module Rails
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
config.assets.css_compressor = nil
|
7
|
+
config.assets.js_compressor = nil
|
8
|
+
rake_tasks do
|
9
|
+
load "tasks/assets/minify/compress.rake"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "assets/minify/version"
|
4
|
+
require_relative "assets/minify/errors"
|
5
|
+
require_relative "assets/minify/compressor"
|
6
|
+
require_relative "assets/minify/output_path"
|
7
|
+
require_relative "assets/minify/railtie"
|
8
|
+
|
9
|
+
module Assets::Minify
|
10
|
+
mattr_accessor :logger, default: Logger.new(STDOUT)
|
11
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :assets_minify do
|
4
|
+
desc "Minify the files"
|
5
|
+
task :compress, :environment do
|
6
|
+
output_path = Assets::Minify::OutputPath.new(
|
7
|
+
::Rails.application.config.assets.output_path
|
8
|
+
)
|
9
|
+
|
10
|
+
output_path.files.each do | file_path |
|
11
|
+
compressor = Assets::Minify::Compressor.new(file_path)
|
12
|
+
case file_path.to_s
|
13
|
+
when /\.js$/
|
14
|
+
next unless compressor.js_compressor
|
15
|
+
File.write(file_path, compressor.js_compress)
|
16
|
+
Assets::Minify.logger.info "Minify #{file_path}"
|
17
|
+
when /\.css$/
|
18
|
+
next unless compressor.css_compressor
|
19
|
+
File.write(file_path, compressor.css_compress)
|
20
|
+
Assets::Minify.logger.info "Minify #{file_path}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if Rake::Task.task_defined?("assets:precompile")
|
27
|
+
Rake::Task['assets:precompile'].enhance do
|
28
|
+
Rake::Task['assets_minify:compress'].invoke
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: assets-minify-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yubele
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-03-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 7.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 7.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 7.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 7.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 7.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 7.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Minify with yui-compressor, tester in propshaft.
|
70
|
+
email:
|
71
|
+
- yusuke@newsdict.jp
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- README.md
|
77
|
+
- lib/assets-minify-rails.rb
|
78
|
+
- lib/assets/minify/compressor.rb
|
79
|
+
- lib/assets/minify/errors.rb
|
80
|
+
- lib/assets/minify/output_path.rb
|
81
|
+
- lib/assets/minify/railtie.rb
|
82
|
+
- lib/assets/minify/version.rb
|
83
|
+
- lib/tasks/assets/minify/compress.rake
|
84
|
+
homepage: https://github.com/newsdict/asset-minify-rails
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata:
|
88
|
+
homepage_uri: https://github.com/newsdict/asset-minify-rails
|
89
|
+
changelog_uri: https://github.com/newsdict/asset-minify-rails/releases
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 2.7.0
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubygems_version: 3.3.3
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Minify assets files
|
109
|
+
test_files: []
|