jekyll-webpack 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -1
- data/README.md +29 -0
- data/jekyll-webpack.gemspec +1 -0
- data/lib/jekyll/webpack.rb +26 -4
- data/lib/jekyll/webpack/debouncer.rb +72 -0
- data/lib/jekyll/webpack/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 523320aff087db3fb6bb6ef7961dec12a000f28f626515077778b12481a3258e
|
4
|
+
data.tar.gz: 03f8df4951e4b92f3077025355768197cbb25b07358310da8a62af229410c696
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46ec0bef97d2f23abec854b252de1c8912762769dba87ecc8cdfe3612c5f7d3676a3a301cfe7b755d5137bec9911a4e2d9f269ead92c5651b8969e9ac4789f8c
|
7
|
+
data.tar.gz: 89943a448286163b31ca3846ace76eb7dd85b97b2e768e4818ec17952f4aeb337b8fc4261c411d36633dde7b13d4f0a10930b0ad5c610a661d0d0aa244b7549d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -57,6 +57,35 @@ And you're away! Just run the `jekyll serve` or `jekyll build` commands with wha
|
|
57
57
|
|
58
58
|
There is a `_data/tailwind.yml` file in the fixure site that's picked up by adding a frontmatter declaration in `tailwind.config.js`. This Tailwind config is in turn picked up by the outputted webpack config and parsed when webpack runs.
|
59
59
|
|
60
|
+
### Debouncing Webpack runs
|
61
|
+
Sometimes the webpack build can take a long time. You can configure jekyll-webpack to debounce the build in a number of ways. The options are:-
|
62
|
+
|
63
|
+
- run once (when you first run `serve`)
|
64
|
+
- run every n iterations (specify a number of iterations to skip webpack compilation)
|
65
|
+
- run on watch folder changes (specific a folder to watch and only run webpack when a file in the folder has changed)
|
66
|
+
|
67
|
+
Add the following entries into `_config.yml`
|
68
|
+
|
69
|
+
``` yml
|
70
|
+
// _config.yml
|
71
|
+
|
72
|
+
webpack:
|
73
|
+
debounce:
|
74
|
+
run_once: true
|
75
|
+
|
76
|
+
// or ...
|
77
|
+
webpack:
|
78
|
+
debounce:
|
79
|
+
every: 10
|
80
|
+
|
81
|
+
// or ...
|
82
|
+
webpack:
|
83
|
+
debounce:
|
84
|
+
watch: src
|
85
|
+
```
|
86
|
+
|
87
|
+
This is very useful if you plan to use `jekyll serve` with the `--livereload` option as it can speed up your development time significantly.
|
88
|
+
|
60
89
|
### Cleanup
|
61
90
|
If you wish to clean out unused source files after webpack has run that got included in the compiled site, you need to add an entry into your `_config.yml` like:
|
62
91
|
|
data/jekyll-webpack.gemspec
CHANGED
data/lib/jekyll/webpack.rb
CHANGED
@@ -3,21 +3,40 @@
|
|
3
3
|
require "jekyll/webpack/version"
|
4
4
|
require "jekyll"
|
5
5
|
require "open3"
|
6
|
+
require 'tmpdir'
|
7
|
+
require 'jekyll/webpack/debouncer'
|
6
8
|
|
7
9
|
module Jekyll
|
8
10
|
module Webpack
|
11
|
+
|
12
|
+
@@webpack_debouncers = {}
|
13
|
+
|
9
14
|
class Error < StandardError; end
|
10
15
|
|
11
16
|
def self.build(site)
|
17
|
+
only_in = site.config.dig('webpack', 'only_in')
|
18
|
+
debounce = site.config.dig('webpack', 'debounce')
|
19
|
+
|
12
20
|
site_dest = site.dest
|
21
|
+
webpack_dist_path = File.expand_path('dist', site.dest)
|
13
22
|
|
14
|
-
only_in = site.config.dig('webpack', 'only_in')
|
15
23
|
if only_in
|
16
24
|
entries = []
|
17
25
|
array_or_scalar(only_in) { |entry| entries << site_dest.end_with?(entry) }
|
18
26
|
return unless entries.any? true
|
19
27
|
end
|
20
28
|
|
29
|
+
if debounce
|
30
|
+
@@webpack_debouncers[site.dest] = Debouncer.new(site, debounce) unless @@webpack_debouncers[site.dest]
|
31
|
+
@@webpack_debouncers[site.dest].build { webpack_exec(site_dest) }
|
32
|
+
else
|
33
|
+
webpack_exec(site_dest)
|
34
|
+
end
|
35
|
+
|
36
|
+
cleanup(site)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.webpack_exec(site_dest)
|
21
40
|
stdout, stderr, status = Open3.capture3(
|
22
41
|
"../node_modules/.bin/webpack",
|
23
42
|
chdir: File.expand_path(site_dest)
|
@@ -27,8 +46,6 @@ module Jekyll
|
|
27
46
|
|
28
47
|
raise Error, stderr if stderr.size > 0
|
29
48
|
raise Error, stdout if !runtime_error.nil?
|
30
|
-
|
31
|
-
cleanup(site)
|
32
49
|
end
|
33
50
|
|
34
51
|
def self.cleanup(site)
|
@@ -59,6 +76,11 @@ module Jekyll
|
|
59
76
|
end
|
60
77
|
end
|
61
78
|
|
79
|
+
|
80
|
+
# Jekyll::Hooks.register :site, :after_init do |site|
|
81
|
+
# Jekyll::Webpack.extract_dist(site)
|
82
|
+
# end
|
83
|
+
|
62
84
|
Jekyll::Hooks.register :site, :post_write do |site|
|
63
|
-
|
85
|
+
Jekyll::Webpack.build(site)
|
64
86
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'listen'
|
5
|
+
|
6
|
+
module Jekyll
|
7
|
+
module Webpack
|
8
|
+
class Debouncer
|
9
|
+
attr_reader :site, :dist_path, :config, :run_once, :has_run, :run_every_n, :watch_nodes, :listener
|
10
|
+
|
11
|
+
def initialize(site, debounce_config)
|
12
|
+
@config = debounce_config
|
13
|
+
@run_once = debounce_config.dig('run_once')
|
14
|
+
@run_every_n = debounce_config.dig('every')
|
15
|
+
@watch_nodes = debounce_config.dig('watch')
|
16
|
+
|
17
|
+
if @watch_nodes
|
18
|
+
if Array === @watch_nodes
|
19
|
+
watch_paths = @watch_nodes.map { |file| File.join(site.source, file) }
|
20
|
+
else
|
21
|
+
watch_paths = [@watch_nodes]
|
22
|
+
end
|
23
|
+
|
24
|
+
@listener = Listen.to(*watch_paths) do |modified, added, removed|
|
25
|
+
@has_run = false
|
26
|
+
end
|
27
|
+
@listener.start
|
28
|
+
end
|
29
|
+
|
30
|
+
@run_counter = 0
|
31
|
+
@has_run = false
|
32
|
+
@site = site
|
33
|
+
@dist_tmpdir = Dir.mktmpdir("jekyll_webpack_dist_#{File.split(site.dest).last}")
|
34
|
+
@dist_path = File.expand_path('dist', site.dest)
|
35
|
+
end
|
36
|
+
|
37
|
+
def build
|
38
|
+
if run_once || watch_nodes
|
39
|
+
if has_run
|
40
|
+
restore_dist
|
41
|
+
else
|
42
|
+
yield
|
43
|
+
extract_dist
|
44
|
+
end
|
45
|
+
elsif run_every_n
|
46
|
+
if !has_run
|
47
|
+
yield
|
48
|
+
@run_counter += 1
|
49
|
+
extract_dist
|
50
|
+
elsif run_every_n == @run_counter
|
51
|
+
yield
|
52
|
+
@run_counter = 0
|
53
|
+
extract_dist
|
54
|
+
else
|
55
|
+
restore_dist
|
56
|
+
@run_counter += 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
@has_run = true
|
61
|
+
end
|
62
|
+
|
63
|
+
def extract_dist
|
64
|
+
FileUtils.cp_r(dist_path, @dist_tmpdir)
|
65
|
+
end
|
66
|
+
|
67
|
+
def restore_dist
|
68
|
+
FileUtils.cp_r(File.join(@dist_tmpdir, 'dist'), File.join(site.dest, 'dist'))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-webpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: listen
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,6 +144,7 @@ files:
|
|
130
144
|
- bin/setup
|
131
145
|
- jekyll-webpack.gemspec
|
132
146
|
- lib/jekyll/webpack.rb
|
147
|
+
- lib/jekyll/webpack/debouncer.rb
|
133
148
|
- lib/jekyll/webpack/version.rb
|
134
149
|
homepage: https://github.com/tevio/jekyll-webpack
|
135
150
|
licenses:
|