jekyll-webpack 0.2.2 → 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/.gitignore +1 -0
- data/Gemfile.lock +2 -1
- data/README.md +72 -2
- data/jekyll-webpack.gemspec +1 -0
- data/lib/jekyll/webpack.rb +58 -1
- 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/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,8 +6,6 @@ This plugin will allow you to build your assets with Webpack _after_ Jekyll has
|
|
6
6
|
|
7
7
|
This adds Webpack at a sane point in the build pipeline and will also allow you to parameterize your webpack and other JS config files by prepending them with front matter, before the compilation occurs. You can see a functioning example in the `spec/fixtures` folder:-
|
8
8
|
|
9
|
-
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.
|
10
|
-
|
11
9
|
|
12
10
|
## Installation
|
13
11
|
|
@@ -53,6 +51,78 @@ And the basic JS entrypoint `mkdir src && touch src/index.js`
|
|
53
51
|
|
54
52
|
And you're away! Just run the `jekyll serve` or `jekyll build` commands with whatever env you need.
|
55
53
|
|
54
|
+
## Config
|
55
|
+
|
56
|
+
### Configuring JS config files
|
57
|
+
|
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
|
+
|
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
|
+
|
89
|
+
### Cleanup
|
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:
|
91
|
+
|
92
|
+
``` yml
|
93
|
+
// _config.yml
|
94
|
+
|
95
|
+
webpack:
|
96
|
+
cleanup_files: src
|
97
|
+
|
98
|
+
// or an array
|
99
|
+
|
100
|
+
webpack:
|
101
|
+
cleanup_files:
|
102
|
+
- src
|
103
|
+
- node_modules
|
104
|
+
```
|
105
|
+
|
106
|
+
### Dest inclusion (excluding
|
107
|
+
If want to ensure that webpack only runs in a specific site dest (eg `_site` only, and no subdirectories) you can pass a single path value or an inclusion list of paths you want webpack to run in, at config time, by modifiying the `_config.yml` like so:
|
108
|
+
|
109
|
+
``` yml
|
110
|
+
// _config.yml
|
111
|
+
|
112
|
+
webpack:
|
113
|
+
only_in: _site
|
114
|
+
|
115
|
+
// or as a list
|
116
|
+
webpack:
|
117
|
+
only_in:
|
118
|
+
- _site
|
119
|
+
- _build
|
120
|
+
```
|
121
|
+
|
122
|
+
### Example `_config.yml`
|
123
|
+
You can have a look at the possible configuration options in the fixtures config file at `spec/fixtures/_config.yml` in this repo.
|
124
|
+
|
125
|
+
|
56
126
|
## Development
|
57
127
|
|
58
128
|
After checking out the repo, run `bin/setup` to install dependencies. Then `cd spec/fixtures && yarn` to install required JS dependencies for specs. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/jekyll-webpack.gemspec
CHANGED
data/lib/jekyll/webpack.rb
CHANGED
@@ -3,14 +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)
|
22
|
+
|
23
|
+
if only_in
|
24
|
+
entries = []
|
25
|
+
array_or_scalar(only_in) { |entry| entries << site_dest.end_with?(entry) }
|
26
|
+
return unless entries.any? true
|
27
|
+
end
|
13
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)
|
14
40
|
stdout, stderr, status = Open3.capture3(
|
15
41
|
"../node_modules/.bin/webpack",
|
16
42
|
chdir: File.expand_path(site_dest)
|
@@ -21,9 +47,40 @@ module Jekyll
|
|
21
47
|
raise Error, stderr if stderr.size > 0
|
22
48
|
raise Error, stdout if !runtime_error.nil?
|
23
49
|
end
|
50
|
+
|
51
|
+
def self.cleanup(site)
|
52
|
+
cleanup_files = site.config.dig('webpack', 'cleanup_files')
|
53
|
+
|
54
|
+
if cleanup_files
|
55
|
+
array_or_scalar(cleanup_files) do |dest_for_clean|
|
56
|
+
path = File.expand_path(dest_for_clean, site.dest)
|
57
|
+
|
58
|
+
if File.exists?(path) || Dir.exists?(path)
|
59
|
+
FileUtils.rm_rf(path)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def self.array_or_scalar(value)
|
68
|
+
if Array === value
|
69
|
+
value.each do |entry|
|
70
|
+
yield entry
|
71
|
+
end
|
72
|
+
else
|
73
|
+
yield value
|
74
|
+
end
|
75
|
+
end
|
24
76
|
end
|
25
77
|
end
|
26
78
|
|
79
|
+
|
80
|
+
# Jekyll::Hooks.register :site, :after_init do |site|
|
81
|
+
# Jekyll::Webpack.extract_dist(site)
|
82
|
+
# end
|
83
|
+
|
27
84
|
Jekyll::Hooks.register :site, :post_write do |site|
|
28
|
-
|
85
|
+
Jekyll::Webpack.build(site)
|
29
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:
|