jekyll-simple-assets 0.3.1 → 0.6.1
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/Gemfile.lock +18 -14
- data/README.md +66 -0
- data/jekyll-simple-assets.gemspec +1 -0
- data/lib/jekyll-simple-assets/content-hash.rb +4 -9
- data/lib/jekyll-simple-assets/critical.rb +28 -16
- data/lib/jekyll-simple-assets/esbuild.rb +93 -0
- data/lib/jekyll-simple-assets/terser.rb +100 -0
- data/lib/jekyll-simple-assets/version.rb +1 -1
- data/lib/jekyll-simple-assets.rb +54 -3
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de767c626fd0732f43f0922b71ff3b0ef130be4ca6f28f0debd0f33f75df2cd5
|
4
|
+
data.tar.gz: 49430a9031fd6cfb541c76f80c346fc8782287cb31fc5446eb31da030dc7ae55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3477b5d323c0a8c0ca927a953e8420981c17711799be68ead1d59d2f0ca047406b2b05ebcd6c480cfb519f39025e7f1991e0e1b7d6ded306875191cba865d71
|
7
|
+
data.tar.gz: 6d3d2a4a85fb4f8f55a01cea832dc58e23e49d4f522e8b765f5558c7e2f755b1be29f12246152e835c8f7e03a41118c1fd717d1d460a57a2d51809c7b6223c18
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
jekyll-simple-assets (0.
|
4
|
+
jekyll-simple-assets (0.6.0)
|
5
5
|
css_parser
|
6
6
|
jekyll
|
7
|
+
terser
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
@@ -11,59 +12,62 @@ GEM
|
|
11
12
|
addressable (2.7.0)
|
12
13
|
public_suffix (>= 2.0.2, < 5.0)
|
13
14
|
colorator (1.1.0)
|
14
|
-
concurrent-ruby (1.1.
|
15
|
-
css_parser (1.
|
15
|
+
concurrent-ruby (1.1.8)
|
16
|
+
css_parser (1.9.0)
|
16
17
|
addressable
|
17
|
-
em-websocket (0.5.
|
18
|
+
em-websocket (0.5.2)
|
18
19
|
eventmachine (>= 0.12.9)
|
19
20
|
http_parser.rb (~> 0.6.0)
|
20
21
|
eventmachine (1.2.7)
|
21
|
-
|
22
|
+
execjs (2.7.0)
|
23
|
+
ffi (1.15.0)
|
22
24
|
forwardable-extended (2.6.0)
|
23
25
|
http_parser.rb (0.6.0)
|
24
|
-
i18n (1.8.
|
26
|
+
i18n (1.8.9)
|
25
27
|
concurrent-ruby (~> 1.0)
|
26
|
-
jekyll (4.
|
28
|
+
jekyll (4.2.0)
|
27
29
|
addressable (~> 2.4)
|
28
30
|
colorator (~> 1.0)
|
29
31
|
em-websocket (~> 0.5)
|
30
32
|
i18n (~> 1.0)
|
31
33
|
jekyll-sass-converter (~> 2.0)
|
32
34
|
jekyll-watch (~> 2.0)
|
33
|
-
kramdown (~> 2.
|
35
|
+
kramdown (~> 2.3)
|
34
36
|
kramdown-parser-gfm (~> 1.0)
|
35
37
|
liquid (~> 4.0)
|
36
38
|
mercenary (~> 0.4.0)
|
37
39
|
pathutil (~> 0.9)
|
38
40
|
rouge (~> 3.0)
|
39
41
|
safe_yaml (~> 1.0)
|
40
|
-
terminal-table (~>
|
42
|
+
terminal-table (~> 2.0)
|
41
43
|
jekyll-sass-converter (2.1.0)
|
42
44
|
sassc (> 2.0.1, < 3.0)
|
43
45
|
jekyll-watch (2.2.1)
|
44
46
|
listen (~> 3.0)
|
45
|
-
kramdown (2.
|
47
|
+
kramdown (2.3.1)
|
46
48
|
rexml
|
47
49
|
kramdown-parser-gfm (1.1.0)
|
48
50
|
kramdown (~> 2.0)
|
49
51
|
liquid (4.0.3)
|
50
|
-
listen (3.
|
52
|
+
listen (3.5.0)
|
51
53
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
52
54
|
rb-inotify (~> 0.9, >= 0.9.10)
|
53
55
|
mercenary (0.4.0)
|
54
56
|
pathutil (0.16.2)
|
55
57
|
forwardable-extended (~> 2.6)
|
56
|
-
public_suffix (4.0.
|
58
|
+
public_suffix (4.0.6)
|
57
59
|
rb-fsevent (0.10.4)
|
58
60
|
rb-inotify (0.10.1)
|
59
61
|
ffi (~> 1.0)
|
60
62
|
rexml (3.2.4)
|
61
|
-
rouge (3.
|
63
|
+
rouge (3.26.0)
|
62
64
|
safe_yaml (1.0.5)
|
63
65
|
sassc (2.4.0)
|
64
66
|
ffi (~> 1.9)
|
65
|
-
terminal-table (
|
67
|
+
terminal-table (2.0.0)
|
66
68
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
69
|
+
terser (1.1.3)
|
70
|
+
execjs (>= 0.3.0, < 3)
|
67
71
|
unicode-display_width (1.7.0)
|
68
72
|
|
69
73
|
PLATFORMS
|
data/README.md
CHANGED
@@ -23,6 +23,7 @@ Returns a base64 encoded md5 hash based on the contents of the path given.
|
|
23
23
|
|
24
24
|
Returns a relative url to the path given, with a hash based on the content of
|
25
25
|
the file as a query string.
|
26
|
+
Will link to a minified version of the file if possible.
|
26
27
|
|
27
28
|
```liquid
|
28
29
|
{% asset assets/js/app.js %}
|
@@ -58,6 +59,15 @@ Returns an md5 hash of the input string.
|
|
58
59
|
{{ 'some text' | md5 }}
|
59
60
|
```
|
60
61
|
|
62
|
+
#### uglify
|
63
|
+
|
64
|
+
Minifies javascript given as an input string (uses terser, and terser settings
|
65
|
+
even though the filter is called `uglify`
|
66
|
+
|
67
|
+
```liquid
|
68
|
+
{{ 'const foo = "bar"' | uglify }}
|
69
|
+
```
|
70
|
+
|
61
71
|
## Content hashes
|
62
72
|
|
63
73
|
How the content hashes work is by generating a placeholder string that is
|
@@ -77,6 +87,48 @@ This plugin can also be used to generate critical css stylesheets. See
|
|
77
87
|
configuration for more information on doing this. To generate critical css,
|
78
88
|
[critical](https://github.com/addyosmani/critical) must be installed.
|
79
89
|
|
90
|
+
## Javascript/Typescript bundling
|
91
|
+
|
92
|
+
This plugin can also be used to bundle javascript and typescript files and
|
93
|
+
modules using esbuild. Node modules can be included just by requiring them.
|
94
|
+
Local modules can be required under the `@simple-assets` namespace, which
|
95
|
+
will look for js files in the `_js` and `_ts` directories.
|
96
|
+
|
97
|
+
For example:
|
98
|
+
```javascript
|
99
|
+
// assets/js/main.js
|
100
|
+
|
101
|
+
// require node_module
|
102
|
+
var leftpad = require('left-pad');
|
103
|
+
|
104
|
+
// will look for left-pad.js or left-pad.ts at _js/ or _ts/ in the
|
105
|
+
// project root
|
106
|
+
var rightpad = require('@simple-assets/right-pad');
|
107
|
+
```
|
108
|
+
|
109
|
+
You can also put variables in the liquid frontmatter of a js/ts file (that is
|
110
|
+
not under `_js` or `_ts`) to configure esbuild.
|
111
|
+
|
112
|
+
```liquid
|
113
|
+
---
|
114
|
+
bundle: false # don't bundle or run esbuild on this file
|
115
|
+
esbuild_flags: --target=es5 # pass any flags to esbuild for this file
|
116
|
+
---
|
117
|
+
```
|
118
|
+
|
119
|
+
To bundle javascript [esbuild](https://github.com/evanw/esbuild) must be
|
120
|
+
installed.
|
121
|
+
|
122
|
+
## Javascript minification
|
123
|
+
|
124
|
+
The terser package is also included and will minify files if `terser_enabled`
|
125
|
+
is set to true in config.yml, or if JEKYLL_ENV is set to production. Any
|
126
|
+
options can be passed to terser under the `terser` key in config.yml
|
127
|
+
(see configuration for example, or
|
128
|
+
[here](https://github.com/ahorek/terser-ruby) for detailed options).
|
129
|
+
Additionally you can set terser settings in the liquid frontmatter of a js file
|
130
|
+
in the same manner as in config.yml, also under the `terser` key.
|
131
|
+
|
80
132
|
## Configuration
|
81
133
|
|
82
134
|
```
|
@@ -86,6 +138,10 @@ simple_assets:
|
|
86
138
|
# default: false
|
87
139
|
hashing_enabled: true
|
88
140
|
|
141
|
+
# If set to true, source maps will be generated for javascript
|
142
|
+
# default: false
|
143
|
+
source_maps_enabled: true
|
144
|
+
|
89
145
|
# The length of the content hashes generated.
|
90
146
|
# default: 16
|
91
147
|
hash_length: 8
|
@@ -109,4 +165,14 @@ simple_assets:
|
|
109
165
|
layout: post
|
110
166
|
# If the rules should be removed from the original source css files
|
111
167
|
extract: true
|
168
|
+
|
169
|
+
# Options for bundling javascript/typescript with the `esbuild` npm module
|
170
|
+
# Set to true to enable
|
171
|
+
bundle: true
|
172
|
+
|
173
|
+
# Options for javascript minification with terser
|
174
|
+
terser:
|
175
|
+
# any options for terser can be put here and will be passed to it
|
176
|
+
output:
|
177
|
+
ascii_only: true
|
112
178
|
```
|
@@ -155,7 +155,10 @@ def self.replace_placeholders_for_path (page_path, input)
|
|
155
155
|
replacement = SimpleAssets::asset_contenthash_map[asset_path]
|
156
156
|
|
157
157
|
if type == 'path'
|
158
|
-
|
158
|
+
min_path = asset_path.sub(/\.([^\.]*?)$/, '.min.\1')
|
159
|
+
url = (File.file? File.join(SimpleAssets::site.config['destination'], min_path)) ? min_path : asset_path
|
160
|
+
|
161
|
+
replacement = "#{ url }?v=#{ replacement }"
|
159
162
|
|
160
163
|
replacement = SimpleAssets::relative_url(replacement)
|
161
164
|
end
|
@@ -170,14 +173,6 @@ def self.replace_placeholders_for_path (page_path, input)
|
|
170
173
|
output
|
171
174
|
end
|
172
175
|
|
173
|
-
def self.replace_placeholders_for_asset (doc, site)
|
174
|
-
page_path = doc.path.sub("#{ site.config['source'] }/", '')
|
175
|
-
|
176
|
-
return unless SimpleAssets::page_assets_map[page_path]
|
177
|
-
|
178
|
-
doc.output = SimpleAssets::replace_placeholders_for_path(page_path, doc.output)
|
179
|
-
end
|
180
|
-
|
181
176
|
|
182
177
|
end
|
183
178
|
end
|
@@ -7,19 +7,22 @@ module Jekyll
|
|
7
7
|
module SimpleAssets
|
8
8
|
|
9
9
|
|
10
|
-
def self.critical_css_source_files
|
11
|
-
@@critical_css_source_files ||=
|
10
|
+
def self.critical_css_source_files ()
|
11
|
+
@@critical_css_source_files ||= {}
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.make_temp_css_files_for_critical (asset)
|
15
15
|
SimpleAssets::config['critical_css']['css_files'].each do |path|
|
16
16
|
next unless asset.path == path || asset.path == path.sub(/\.css$/, '.scss')
|
17
17
|
|
18
|
-
f = Tempfile.new('css-source')
|
18
|
+
f = Tempfile.new([ 'css-source', '.css' ])
|
19
19
|
f.write asset.output
|
20
20
|
f.close
|
21
|
+
File.chmod(0755, f.path)
|
21
22
|
|
22
|
-
SimpleAssets
|
23
|
+
Jekyll.logger.debug("SimpleAssets:", "Created new temp file for css: #{ asset.path } at: #{ f.path }")
|
24
|
+
|
25
|
+
SimpleAssets::critical_css_source_files[path] = { 'file' => f, 'page' => asset }
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
@@ -40,7 +43,7 @@ end
|
|
40
43
|
def self.generate_critical_css (site)
|
41
44
|
css_files_str = ''
|
42
45
|
|
43
|
-
SimpleAssets::critical_css_source_files.each do |f|
|
46
|
+
SimpleAssets::critical_css_source_files.each do |_, f|
|
44
47
|
css_files_str += "--css #{ f['file'].path } "
|
45
48
|
|
46
49
|
f['css'] = CssParser::Parser.new
|
@@ -60,13 +63,16 @@ def self.generate_critical_css (site)
|
|
60
63
|
stdin.write(html)
|
61
64
|
stdin.close
|
62
65
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
Jekyll.logger.
|
66
|
+
if !wait_thr.value.success? || stderr.read != ''
|
67
|
+
Jekyll.logger.error("SimpleAssets:", 'Critical (css) error:')
|
68
|
+
stderr.each do |line|
|
69
|
+
Jekyll.logger.error("", line)
|
70
|
+
end
|
71
|
+
elsif stderr.read != ''
|
72
|
+
Jekyll.logger.error("SimpleAssets:", 'Critical (css) error:')
|
73
|
+
stderr.each do |line|
|
74
|
+
Jekyll.logger.error("", line)
|
75
|
+
end
|
70
76
|
end
|
71
77
|
|
72
78
|
critical_css_str = stdout.read
|
@@ -88,7 +94,7 @@ def self.generate_critical_css (site)
|
|
88
94
|
|
89
95
|
critical_css.load_string! critical_css_str
|
90
96
|
|
91
|
-
SimpleAssets::critical_css_source_files.each do |f|
|
97
|
+
SimpleAssets::critical_css_source_files.each do |_, f|
|
92
98
|
f['css'].each_rule_set do |source_rule_set, source_media_type|
|
93
99
|
critical_css.each_rule_set do |critical_rule_set, critical_media_type|
|
94
100
|
if critical_rule_set.selectors.join(',') == source_rule_set.selectors.join(',')
|
@@ -104,13 +110,19 @@ def self.generate_critical_css (site)
|
|
104
110
|
end
|
105
111
|
end
|
106
112
|
|
107
|
-
SimpleAssets::critical_css_source_files.each do |f|
|
108
|
-
|
113
|
+
SimpleAssets::critical_css_source_files.each do |_, f|
|
114
|
+
leftover_css = f['css'].to_s if f['extract']
|
115
|
+
|
116
|
+
# css_parser leaves blank keyframes so fix them
|
117
|
+
keyframes = f['page'].output.scan(/@keyframes\s+(?:.*?)\s*{(?:\s*\S*?\s*{.*?}\s*)+}/m)
|
118
|
+
keyframes.each { |keyframe| leftover_css += keyframe }
|
119
|
+
|
120
|
+
f['page'].output
|
109
121
|
end
|
110
122
|
end
|
111
123
|
|
112
124
|
def self.resolve_critical_css_content_hashes (site)
|
113
|
-
SimpleAssets::critical_css_source_files.each do |source_file|
|
125
|
+
SimpleAssets::critical_css_source_files.each do |_, source_file|
|
114
126
|
page = source_file['page']
|
115
127
|
page_path = page.path.sub("#{ site.config['source'] }/", '')
|
116
128
|
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module SimpleAssets
|
3
|
+
|
4
|
+
def self.generate_esbuild_config_file ()
|
5
|
+
source_path = Jekyll::SimpleAssets::site.config['source']
|
6
|
+
|
7
|
+
tsconfig_path = File.join(source_path, 'jsconfig.json')
|
8
|
+
jsconfig_path = File.join(source_path, 'tsconfig.json')
|
9
|
+
|
10
|
+
config = {}
|
11
|
+
|
12
|
+
if File.file?(tsconfig_path)
|
13
|
+
config = JSON.parse(File.read(tsconfig_path))
|
14
|
+
elsif File.file?(jsconfig_path)
|
15
|
+
config = JSON.parse(File.read(jsconfig_path))
|
16
|
+
end
|
17
|
+
|
18
|
+
f = Tempfile.new([ 'jsconfig.esbuild.', '.json' ])
|
19
|
+
|
20
|
+
config['compilerOptions'] = {} unless config['compilerOptions']
|
21
|
+
|
22
|
+
base_url = source_path
|
23
|
+
if config['compilerOptions']['baseUrl']
|
24
|
+
base_url = File.join(source_path, config['compilerOptions']['baseUrl'])
|
25
|
+
end
|
26
|
+
config['compilerOptions']['baseUrl'] = Pathname.new(base_url).relative_path_from(Pathname.new(f.path))
|
27
|
+
|
28
|
+
config['compilerOptions']['paths'] = {} unless config['compilerOptions']['paths']
|
29
|
+
|
30
|
+
relative_path = Pathname.new(source_path).relative_path_from(Pathname.new(base_url))
|
31
|
+
|
32
|
+
config['compilerOptions']['paths']['@simple-assets/*'] = [
|
33
|
+
File.join(relative_path, '_js/*'),
|
34
|
+
File.join(relative_path, '_ts/*'),
|
35
|
+
]
|
36
|
+
|
37
|
+
f.write config.to_json
|
38
|
+
f.close
|
39
|
+
File.chmod(0755, f.path)
|
40
|
+
|
41
|
+
Jekyll::SimpleAssets::esbuild_config_file(f)
|
42
|
+
|
43
|
+
Jekyll.logger.debug("SimpleAssets:", "esbuild: using tsconfig #{ f.path }")
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.esbuild_bundle_file (page, payload, config_path)
|
47
|
+
if page.data['bundle'] == false
|
48
|
+
return
|
49
|
+
end
|
50
|
+
|
51
|
+
bundle_cmd = "npx esbuild --bundle --tsconfig=#{ config_path }"
|
52
|
+
|
53
|
+
if page.data['esbuild_flags']
|
54
|
+
bundle_cmd += ' ' + page.data['esbuild_flags']
|
55
|
+
end
|
56
|
+
|
57
|
+
node_env = '--define:process.env.NODE_ENV="' + (ENV['JEKYLL_ENV'] != 'production' ? "'development'" : "'production'") + '"'
|
58
|
+
|
59
|
+
bundle_cmd += ' ' + node_env + " --sourcefile=#{ page.path[/[^\/]*$/] }"
|
60
|
+
|
61
|
+
if SimpleAssets::source_maps_enabled?
|
62
|
+
bundle_cmd += ' ' + '--sourcemap=inline'
|
63
|
+
end
|
64
|
+
|
65
|
+
dir = File.dirname(page.path)
|
66
|
+
|
67
|
+
Jekyll.logger.info("SimpleAssets:", 'bundling: ' + page.path)
|
68
|
+
Jekyll.logger.debug("SimpleAssets:", 'running command: ' + bundle_cmd)
|
69
|
+
|
70
|
+
Open3.popen3(bundle_cmd, :chdir => dir) do |stdin, stdout, stderr, wait_thr|
|
71
|
+
stdin.write(page.output)
|
72
|
+
stdin.close
|
73
|
+
|
74
|
+
bundled = stdout.read
|
75
|
+
|
76
|
+
if !wait_thr.value.success? || stderr.read != ''
|
77
|
+
Jekyll.logger.error("SimpleAssets:", 'esbuild error:')
|
78
|
+
stderr.each do |line|
|
79
|
+
Jekyll.logger.error("", line)
|
80
|
+
end
|
81
|
+
elsif stderr.read != ''
|
82
|
+
Jekyll.logger.error("SimpleAssets:", 'esbuild error:')
|
83
|
+
stderr.each do |line|
|
84
|
+
Jekyll.logger.error("", line)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
page.output = bundled
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'terser'
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
|
6
|
+
module SimpleAssets
|
7
|
+
def self.symbolize_keys (hash)
|
8
|
+
return {} if hash.nil?
|
9
|
+
|
10
|
+
hash.inject({}) do |result, (key, value)|
|
11
|
+
|
12
|
+
new_key = case key
|
13
|
+
when String then key.to_sym
|
14
|
+
else key
|
15
|
+
end
|
16
|
+
new_value = case value
|
17
|
+
when Hash then symbolize_keys(value)
|
18
|
+
else value
|
19
|
+
end
|
20
|
+
|
21
|
+
if new_value.is_a?(String) and new_value.match(/^\/.*\/$/)
|
22
|
+
new_value = /#{ Regexp.quote(new_value[1..-2]) }/
|
23
|
+
end
|
24
|
+
|
25
|
+
result[new_key] = new_value
|
26
|
+
|
27
|
+
result
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.merge_recursively(a, b)
|
32
|
+
a.merge(b) {|key, a_item, b_item| SimpleAssets::merge_recursively(a_item, b_item) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.should_minify_file? (page)
|
36
|
+
return false unless page.respond_to? :output
|
37
|
+
return false unless SimpleAssets::terser_enabled?
|
38
|
+
return false if page.data['do_not_compress'] == true
|
39
|
+
return true
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.minify_file (page)
|
43
|
+
return unless SimpleAssets::should_minify_file?(page)
|
44
|
+
|
45
|
+
site_config = symbolize_keys(SimpleAssets::site.config['simple_assets']['terser'])
|
46
|
+
page_config = symbolize_keys(page.data['terser'])
|
47
|
+
|
48
|
+
config = SimpleAssets::merge_recursively(site_config || {}, page_config || {})
|
49
|
+
|
50
|
+
map_path = page.path + '.map'
|
51
|
+
if SimpleAssets::source_maps_enabled?
|
52
|
+
config = SimpleAssets::merge_recursively(config, {
|
53
|
+
:source_map => { :filename => page.path[/[^\/]*$/], :url => true },
|
54
|
+
})
|
55
|
+
|
56
|
+
minified, source_map = Terser.new(config).compile_with_map(page.output)
|
57
|
+
else
|
58
|
+
minified = Terser.new(config).compile(page.output)
|
59
|
+
end
|
60
|
+
|
61
|
+
min_path = page.path.sub(/\.(j|t)s$/i, '.min.js')
|
62
|
+
Jekyll.logger.info("SimpleAssets:", 'minified: ' + min_path)
|
63
|
+
|
64
|
+
if source_map
|
65
|
+
File.write(File.join(SimpleAssets::site.config['destination'], map_path), source_map)
|
66
|
+
minified = minified.gsub(/^\/\/#\s*?source(Mapping)?URL=.*$/, '')
|
67
|
+
minified += "\n//# sourceMappingURL=#{ SimpleAssets::relative_url(map_path) }"
|
68
|
+
|
69
|
+
Jekyll.logger.debug("SimpleAssets:", 'created source map: ' + map_path)
|
70
|
+
|
71
|
+
SimpleAssets::site.config['keep_files'] << map_path
|
72
|
+
end
|
73
|
+
|
74
|
+
if SimpleAssets::page_assets_map[page.path]
|
75
|
+
SimpleAssets::page_assets_map[min_path] = SimpleAssets::page_assets_map[page.path]
|
76
|
+
end
|
77
|
+
|
78
|
+
SimpleAssets::site.config['keep_files'] << min_path
|
79
|
+
|
80
|
+
return min_path, minified
|
81
|
+
end
|
82
|
+
|
83
|
+
module UglifyFilter
|
84
|
+
def uglify (input)
|
85
|
+
return if input.nil?
|
86
|
+
|
87
|
+
return input.split('\n').join('\\\n') unless SimpleAssets::terser_enabled?
|
88
|
+
|
89
|
+
config = @context.registers[:site].config['simple_assets']
|
90
|
+
|
91
|
+
terser_config = SimpleAssets::symbolize_keys(config['terser'])
|
92
|
+
|
93
|
+
Terser.new(terser_config).compile(input)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
Liquid::Template.register_filter(Jekyll::SimpleAssets::UglifyFilter)
|
data/lib/jekyll-simple-assets.rb
CHANGED
@@ -7,11 +7,15 @@ require 'shellwords'
|
|
7
7
|
|
8
8
|
require 'jekyll-simple-assets/content-hash'
|
9
9
|
require 'jekyll-simple-assets/critical'
|
10
|
+
require 'jekyll-simple-assets/esbuild'
|
11
|
+
require 'jekyll-simple-assets/terser'
|
10
12
|
|
11
13
|
module Jekyll
|
12
14
|
module SimpleAssets
|
13
|
-
def self.site (site)
|
14
|
-
@@site
|
15
|
+
def self.site (site = nil)
|
16
|
+
@@site = site if site
|
17
|
+
|
18
|
+
@@site
|
15
19
|
end
|
16
20
|
|
17
21
|
def self.config
|
@@ -26,6 +30,22 @@ module Jekyll
|
|
26
30
|
config.key?('critical_css')
|
27
31
|
end
|
28
32
|
|
33
|
+
def self.esbuild_enabled?
|
34
|
+
config.key?('bundle') && config['bundle'] != false
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.esbuild_config_file (file = nil)
|
38
|
+
@@esbuild_config_file ||= file
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.terser_enabled?
|
42
|
+
config['terser_enabled'] || ENV['JEKYLL_ENV'] == 'production'
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.source_maps_enabled?
|
46
|
+
config['source_maps_enabled']
|
47
|
+
end
|
48
|
+
|
29
49
|
module SimpleAssetsFilters
|
30
50
|
def md5 (input)
|
31
51
|
Digest::MD5.hexdigest(input)
|
@@ -105,7 +125,38 @@ Jekyll::Hooks.register :site, :post_render, priority: :low do |site, payload|
|
|
105
125
|
end
|
106
126
|
|
107
127
|
potential_pages.each do |doc|
|
108
|
-
|
128
|
+
page_path = doc.path.sub("#{ site.config['source'] }/", '')
|
129
|
+
|
130
|
+
if Jekyll::SimpleAssets::page_assets_map[page_path]
|
131
|
+
doc.output = Jekyll::SimpleAssets::replace_placeholders_for_path(page_path, doc.output)
|
132
|
+
end
|
133
|
+
|
134
|
+
if doc.extname =~ /^\.(j|t)s$/i and Jekyll::SimpleAssets::should_minify_file?(doc)
|
135
|
+
min_path, minified = Jekyll::SimpleAssets::minify_file(doc)
|
136
|
+
|
137
|
+
if min_path and Jekyll::SimpleAssets::page_assets_map[page_path]
|
138
|
+
minified = Jekyll::SimpleAssets::replace_placeholders_for_path(page_path, minified)
|
139
|
+
end
|
140
|
+
|
141
|
+
File.write(File.join(Jekyll::SimpleAssets::site.config['destination'], min_path), minified)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
Jekyll::Hooks.register :pages, :post_render do |page, payload|
|
148
|
+
unless Jekyll::SimpleAssets::esbuild_config_file
|
149
|
+
Jekyll::SimpleAssets::generate_esbuild_config_file()
|
150
|
+
end
|
151
|
+
|
152
|
+
if page.extname =~ /^\.(j|t)s$/i
|
153
|
+
if Jekyll::SimpleAssets::esbuild_enabled?
|
154
|
+
Jekyll::SimpleAssets::esbuild_bundle_file(page, payload, Jekyll::SimpleAssets::esbuild_config_file.path)
|
155
|
+
end
|
156
|
+
|
157
|
+
if Jekyll::SimpleAssets::should_minify_file?(page)
|
158
|
+
min_path = page.path.sub(/\.(j|t)s$/i, '.min.js')
|
159
|
+
File.write(File.join(Jekyll::SimpleAssets::site.config['destination'], min_path), '')
|
109
160
|
end
|
110
161
|
end
|
111
162
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-simple-assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sophie Askew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: terser
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,6 +82,8 @@ files:
|
|
68
82
|
- lib/jekyll-simple-assets.rb
|
69
83
|
- lib/jekyll-simple-assets/content-hash.rb
|
70
84
|
- lib/jekyll-simple-assets/critical.rb
|
85
|
+
- lib/jekyll-simple-assets/esbuild.rb
|
86
|
+
- lib/jekyll-simple-assets/terser.rb
|
71
87
|
- lib/jekyll-simple-assets/version.rb
|
72
88
|
homepage: https://github.com/syldexiahime/jekyll-simple-assets
|
73
89
|
licenses:
|