jekyll-simple-assets 0.3.1 → 0.4.0
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 +36 -0
- data/lib/jekyll-simple-assets.rb +22 -1
- data/lib/jekyll-simple-assets/critical.rb +10 -7
- data/lib/jekyll-simple-assets/esbuild.rb +84 -0
- data/lib/jekyll-simple-assets/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cb1966e7b454db1edfa880583d7ae1e9342cde2614435f1d297f0e8f7dd280a
|
4
|
+
data.tar.gz: aa8d28e89449c5af18e1cb43f22723d7cc0be644991bcac971fa5b7786de66c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 434b43a8291227d93d6f385e364101a226abd6405147f0dec9e98219093aa0c55f4ccde0a0a5680946e44bdb38513f0196da1287121dd777a7838201bcb2e1fd
|
7
|
+
data.tar.gz: c38b73fd7c9efbfa362221367bcd3362792f5377682161ecff673d0da2d9fda03fc0349163a47bbbe43ea7df6759a9b6dd221fe4c1b9017f0b3d2cce23782833
|
data/README.md
CHANGED
@@ -77,6 +77,38 @@ This plugin can also be used to generate critical css stylesheets. See
|
|
77
77
|
configuration for more information on doing this. To generate critical css,
|
78
78
|
[critical](https://github.com/addyosmani/critical) must be installed.
|
79
79
|
|
80
|
+
## Javascript/Typescript bundling
|
81
|
+
|
82
|
+
This plugin can also be used to bundle javascript and typescript files and
|
83
|
+
modules using esbuild. Node modules can be included just by requiring them.
|
84
|
+
Local modules can be required under the `@simple-assets` namespace, which
|
85
|
+
will look for js files in the `_js` and `_ts` directories.
|
86
|
+
|
87
|
+
For example:
|
88
|
+
```javascript
|
89
|
+
// assets/js/main.js
|
90
|
+
|
91
|
+
// require node_module
|
92
|
+
var leftpad = require('left-pad');
|
93
|
+
|
94
|
+
// will look for left-pad.js or left-pad.ts at _js/ or _ts/ in the
|
95
|
+
// project root
|
96
|
+
var rightpad = require('@simple-assets/right-pad');
|
97
|
+
```
|
98
|
+
|
99
|
+
You can also put variables in the liquid frontmatter of a js/ts file (that is
|
100
|
+
not under `_js` or `_ts`) to configure esbuild.
|
101
|
+
|
102
|
+
```liquid
|
103
|
+
---
|
104
|
+
bundle: false # don't bundle or run esbuild on this file
|
105
|
+
esbuild_flags: --target=es5 # pass any flags to esbuild for this file
|
106
|
+
---
|
107
|
+
```
|
108
|
+
|
109
|
+
To bundle javascript [esbuild](https://github.com/evanw/esbuild) must be
|
110
|
+
installed.
|
111
|
+
|
80
112
|
## Configuration
|
81
113
|
|
82
114
|
```
|
@@ -109,4 +141,8 @@ simple_assets:
|
|
109
141
|
layout: post
|
110
142
|
# If the rules should be removed from the original source css files
|
111
143
|
extract: true
|
144
|
+
|
145
|
+
# Options for bundling javascript/typescript with the `esbuild` npm module
|
146
|
+
# Set to true to enable
|
147
|
+
bundle: true
|
112
148
|
```
|
data/lib/jekyll-simple-assets.rb
CHANGED
@@ -7,10 +7,11 @@ 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'
|
10
11
|
|
11
12
|
module Jekyll
|
12
13
|
module SimpleAssets
|
13
|
-
def self.site (site)
|
14
|
+
def self.site (site = nil)
|
14
15
|
@@site ||= site
|
15
16
|
end
|
16
17
|
|
@@ -26,6 +27,14 @@ module Jekyll
|
|
26
27
|
config.key?('critical_css')
|
27
28
|
end
|
28
29
|
|
30
|
+
def self.esbuild_enabled?
|
31
|
+
config.key?('bundle') && config['bundle'] != false
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.esbuild_config_file (file = nil)
|
35
|
+
@@esbuild_config_file ||= file
|
36
|
+
end
|
37
|
+
|
29
38
|
module SimpleAssetsFilters
|
30
39
|
def md5 (input)
|
31
40
|
Digest::MD5.hexdigest(input)
|
@@ -110,6 +119,18 @@ Jekyll::Hooks.register :site, :post_render, priority: :low do |site, payload|
|
|
110
119
|
end
|
111
120
|
end
|
112
121
|
|
122
|
+
Jekyll::Hooks.register :pages, :post_render do |page, payload|
|
123
|
+
next unless Jekyll::SimpleAssets::esbuild_enabled?
|
124
|
+
|
125
|
+
unless Jekyll::SimpleAssets::esbuild_config_file
|
126
|
+
Jekyll::SimpleAssets::generate_esbuild_config_file()
|
127
|
+
end
|
128
|
+
|
129
|
+
if page.extname =~ /^\.(j|t)s$/i
|
130
|
+
Jekyll::SimpleAssets::esbuild_bundle_file(page, payload, Jekyll::SimpleAssets::esbuild_config_file.path)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
113
134
|
Jekyll::Hooks.register :site, :post_read do |site|
|
114
135
|
css_pages = [];
|
115
136
|
|
@@ -60,13 +60,16 @@ def self.generate_critical_css (site)
|
|
60
60
|
stdin.write(html)
|
61
61
|
stdin.close
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
Jekyll.logger.
|
63
|
+
if !wait_thr.value.success? || stderr.read != ''
|
64
|
+
Jekyll.logger.error("SimpleAssets:", 'Critical (css) error:')
|
65
|
+
stderr.each do |line|
|
66
|
+
Jekyll.logger.error("", line)
|
67
|
+
end
|
68
|
+
elsif stderr.read != ''
|
69
|
+
Jekyll.logger.error("SimpleAssets:", 'Critical (css) error:')
|
70
|
+
stderr.each do |line|
|
71
|
+
Jekyll.logger.error("", line)
|
72
|
+
end
|
70
73
|
end
|
71
74
|
|
72
75
|
critical_css_str = stdout.read
|
@@ -0,0 +1,84 @@
|
|
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
|
+
|
40
|
+
Jekyll::SimpleAssets::esbuild_config_file(f)
|
41
|
+
|
42
|
+
Jekyll.logger.debug("SimpleAssets:", "esbuild: using tsconfig #{ f.path }")
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.esbuild_bundle_file (page, payload, config_path)
|
46
|
+
if page.data['bundle'] == false
|
47
|
+
return
|
48
|
+
end
|
49
|
+
|
50
|
+
bundle_cmd = "npx esbuild --bundle --tsconfig=#{ config_path }"
|
51
|
+
|
52
|
+
if page.data['esbuild_flags']
|
53
|
+
bundle_cmd = "#{ bundle_cmd } #{ page.data['esbuild_flags'] }"
|
54
|
+
end
|
55
|
+
|
56
|
+
dir = File.dirname(page.path)
|
57
|
+
|
58
|
+
Jekyll.logger.info("SimpleAssets:", 'bundling: ' + page.path)
|
59
|
+
Jekyll.logger.debug("SimpleAssets:", 'running command: ' + bundle_cmd)
|
60
|
+
|
61
|
+
Open3.popen3(bundle_cmd, :chdir => dir) do |stdin, stdout, stderr, wait_thr|
|
62
|
+
stdin.write(page.output)
|
63
|
+
stdin.close
|
64
|
+
|
65
|
+
bundled = stdout.read
|
66
|
+
|
67
|
+
if !wait_thr.value.success? || stderr.read != ''
|
68
|
+
Jekyll.logger.error("SimpleAssets:", 'esbuild error:')
|
69
|
+
stderr.each do |line|
|
70
|
+
Jekyll.logger.error("", line)
|
71
|
+
end
|
72
|
+
elsif stderr.read != ''
|
73
|
+
Jekyll.logger.error("SimpleAssets:", 'esbuild error:')
|
74
|
+
stderr.each do |line|
|
75
|
+
Jekyll.logger.error("", line)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
page.output = bundled
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sophie Askew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/jekyll-simple-assets.rb
|
69
69
|
- lib/jekyll-simple-assets/content-hash.rb
|
70
70
|
- lib/jekyll-simple-assets/critical.rb
|
71
|
+
- lib/jekyll-simple-assets/esbuild.rb
|
71
72
|
- lib/jekyll-simple-assets/version.rb
|
72
73
|
homepage: https://github.com/syldexiahime/jekyll-simple-assets
|
73
74
|
licenses:
|