jekyll-minibundle 3.0.0 → 4.0.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/CHANGELOG.md +78 -66
- data/README.md +117 -101
- data/Rakefile +8 -26
- data/jekyll-minibundle.gemspec +5 -11
- data/lib/jekyll/minibundle/asset_bundle.rb +1 -1
- data/lib/jekyll/minibundle/asset_file_drop.rb +1 -3
- data/lib/jekyll/minibundle/asset_file_registry.rb +2 -2
- data/lib/jekyll/minibundle/asset_tag_markup.rb +1 -1
- data/lib/jekyll/minibundle/bundle_file.rb +3 -0
- data/lib/jekyll/minibundle/development_file.rb +2 -0
- data/lib/jekyll/minibundle/hashes.rb +1 -3
- data/lib/jekyll/minibundle/stamp_file.rb +3 -0
- data/lib/jekyll/minibundle/variable_template.rb +3 -1
- data/lib/jekyll/minibundle/variable_template_registry.rb +2 -2
- data/lib/jekyll/minibundle/version.rb +1 -1
- metadata +8 -184
- data/test/fixture/site/_assets/scripts/app.js +0 -5
- data/test/fixture/site/_assets/scripts/dependency.js +0 -4
- data/test/fixture/site/_assets/styles/common.css +0 -2
- data/test/fixture/site/_assets/styles/reset.css +0 -2
- data/test/fixture/site/_bin/remove_comments +0 -4
- data/test/fixture/site/_bin/with_count +0 -15
- data/test/fixture/site/_config.yml +0 -3
- data/test/fixture/site/_layouts/default.html +0 -29
- data/test/fixture/site/_tmp/site.css +0 -3
- data/test/fixture/site/about.html +0 -4
- data/test/fixture/site/assets/site.css +0 -2
- data/test/fixture/site/index.html +0 -4
- data/test/integration/minibundle_development_mode_test.rb +0 -554
- data/test/integration/minibundle_production_mode_test.rb +0 -900
- data/test/integration/ministamp_development_mode_test.rb +0 -235
- data/test/integration/ministamp_production_mode_test.rb +0 -342
- data/test/integration/static_files_as_asset_sources_test.rb +0 -75
- data/test/support/assertions.rb +0 -26
- data/test/support/fixture_config.rb +0 -20
- data/test/support/static_file_config.rb +0 -23
- data/test/support/test_case.rb +0 -175
- data/test/unit/asset_bundle_test.rb +0 -57
- data/test/unit/asset_file_drop_test.rb +0 -66
- data/test/unit/asset_file_registry_test.rb +0 -237
- data/test/unit/asset_tag_markup_test.rb +0 -46
- data/test/unit/bundle_file_properties_test.rb +0 -108
- data/test/unit/bundle_file_writing_test.rb +0 -155
- data/test/unit/development_file_properties_test.rb +0 -97
- data/test/unit/development_file_writing_test.rb +0 -50
- data/test/unit/environment_test.rb +0 -29
- data/test/unit/files_test.rb +0 -61
- data/test/unit/hashes_test.rb +0 -43
- data/test/unit/jekyll_static_file_api_test.rb +0 -172
- data/test/unit/mini_bundle_block_test.rb +0 -125
- data/test/unit/mini_stamp_tag_test.rb +0 -64
- data/test/unit/stamp_file_properties_test.rb +0 -98
- data/test/unit/stamp_file_writing_test.rb +0 -130
- data/test/unit/variable_template_test.rb +0 -121
data/README.md
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
# Jekyll Minibundle plugin
|
|
2
2
|
|
|
3
3
|
[][MinibundleGem]
|
|
4
|
-
[][MinibundleCI]
|
|
5
5
|
|
|
6
6
|
A straightforward asset bundling plugin for [Jekyll], utilizing external
|
|
7
|
-
minification tool of your choice.
|
|
8
|
-
bundling and asset fingerprinting with MD5
|
|
7
|
+
asset conversion/minification tool of your choice. The plugin provides
|
|
8
|
+
asset concatenation for bundling and asset fingerprinting with [MD5]
|
|
9
|
+
digest for cache busting.
|
|
9
10
|
|
|
10
11
|
There are no runtime dependencies, except for the minification tool used
|
|
11
12
|
for bundling (fingerprinting has no dependencies).
|
|
12
13
|
|
|
13
|
-
The plugin requires Jekyll version 3 or 4. It is tested with
|
|
14
|
-
|
|
14
|
+
The plugin requires Jekyll version 3 or 4. It is tested with CRuby 2.7
|
|
15
|
+
and later.
|
|
15
16
|
|
|
16
17
|
The plugin works with Jekyll's watch mode (auto-regeneration, Jekyll
|
|
17
18
|
option `--watch`), but not with incremental feature enabled (Jekyll
|
|
18
19
|
option `--incremental`).
|
|
19
20
|
|
|
21
|
+
Minibundle plugin does not affect the behavior of Jekyll's [built-in
|
|
22
|
+
asset conversion][JekyllBuiltInAssets]. The plugin is designed to
|
|
23
|
+
incorporate the results produced by external asset tools only.
|
|
24
|
+
|
|
20
25
|
## Features
|
|
21
26
|
|
|
22
|
-
There are two features:
|
|
23
|
-
|
|
24
|
-
feature.
|
|
27
|
+
There are two features: fingerprinting with [MD5 digest][MD5] over the
|
|
28
|
+
contents of the asset file (any type of file will do), and asset
|
|
29
|
+
bundling combined with the first feature.
|
|
25
30
|
|
|
26
31
|
Asset bundling consists of concatenation and minification. The plugin
|
|
27
32
|
implements concatenation and leaves choosing the minification tool up to
|
|
@@ -30,12 +35,12 @@ plugin connects to the minifier with standard unix pipe, feeding asset
|
|
|
30
35
|
file contents to it in desired order via standard input, and reads the
|
|
31
36
|
result from standard output.
|
|
32
37
|
|
|
33
|
-
Why is this good? A fingerprint in asset's path is
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
Why is this good? A fingerprint in asset's path is the [recommended
|
|
39
|
+
way][GoogleWebDevHttpCache] to handle caching of static resources,
|
|
40
|
+
because you can allow browsers and intermediate proxies to cache the
|
|
41
|
+
asset for a very long time. Calculating MD5 digest over the contents of
|
|
42
|
+
the file is fast and the resulting digest is reasonably unique to be
|
|
43
|
+
generated automatically.
|
|
39
44
|
|
|
40
45
|
Asset bundling is good for reducing the number of requests to the
|
|
41
46
|
backend upon page load. The minification of stylesheets and JavaScript
|
|
@@ -47,26 +52,26 @@ The plugin ships as a [RubyGem][MinibundleGem]. To install:
|
|
|
47
52
|
|
|
48
53
|
1. Add the following line to the [Gemfile] of your site:
|
|
49
54
|
|
|
50
|
-
```
|
|
55
|
+
```ruby
|
|
51
56
|
gem 'jekyll-minibundle'
|
|
52
57
|
```
|
|
53
58
|
|
|
54
59
|
2. Run `bundle install`.
|
|
55
60
|
|
|
56
61
|
3. Instruct Jekyll to load the gem by adding this line to the
|
|
57
|
-
[configuration file][JekyllConf] of your site (`_config.yml`):
|
|
62
|
+
[configuration file][JekyllConf] of your site (`_config.yml`):
|
|
58
63
|
|
|
59
|
-
```
|
|
64
|
+
```yaml
|
|
60
65
|
plugins:
|
|
61
66
|
- jekyll/minibundle
|
|
62
67
|
```
|
|
63
68
|
|
|
64
69
|
(Use the `gems` key instead of `plugins` for Jekyll older than v3.5.0.)
|
|
65
70
|
|
|
66
|
-
An alternative to using the `plugins` configuration option is to add
|
|
71
|
+
An alternative to using the `plugins` configuration option is to add the
|
|
67
72
|
`_plugins/minibundle.rb` file to your site project with this line:
|
|
68
73
|
|
|
69
|
-
```
|
|
74
|
+
```ruby
|
|
70
75
|
require 'jekyll/minibundle'
|
|
71
76
|
```
|
|
72
77
|
|
|
@@ -76,9 +81,10 @@ Jekyll's `safe` configuration option.
|
|
|
76
81
|
### Asset fingerprinting
|
|
77
82
|
|
|
78
83
|
If you just want to have an MD5 fingerprint in your asset's path, use
|
|
79
|
-
`ministamp` [Liquid] tag in a Liquid template file. For example
|
|
84
|
+
the `ministamp` [Liquid] tag in a Liquid template file. For example,
|
|
85
|
+
fingerprinting CSS styles:
|
|
80
86
|
|
|
81
|
-
```
|
|
87
|
+
```liquid
|
|
82
88
|
<link rel="stylesheet" href="{{ site.baseurl }}/{% ministamp _assets/site.css assets/site.css %}" media="screen, projection">
|
|
83
89
|
```
|
|
84
90
|
|
|
@@ -92,36 +98,44 @@ The tag outputs the asset destination path, encoded for HTML, into
|
|
|
92
98
|
Liquid's template rendering outcome. For example, when `site.baseurl` is
|
|
93
99
|
empty:
|
|
94
100
|
|
|
95
|
-
```
|
|
96
|
-
<link rel="stylesheet" href="/assets/site-390be921ee0eff063817bb5ef2954300.css" media="screen, projection"
|
|
101
|
+
```html
|
|
102
|
+
<link rel="stylesheet" href="/assets/site-390be921ee0eff063817bb5ef2954300.css" media="screen, projection" />
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Another example, this time fingerprinting an image and using the
|
|
106
|
+
[absolute_url][JekyllLiquidFilters] Liquid filter of Jekyll to render
|
|
107
|
+
the absolute URL of the image in the `src` attribute:
|
|
108
|
+
|
|
109
|
+
```liquid
|
|
110
|
+
<img src="{{ "/" | absolute_url }}{% ministamp _assets/dog.jpg assets/dog.jpg %}" alt="My dog smiling to the camera" title="A photo of my dog" width="195" height="258" />
|
|
97
111
|
```
|
|
98
112
|
|
|
99
|
-
This feature
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
113
|
+
This feature can be combined with asset generation tools external to
|
|
114
|
+
Jekyll. For example, you can configure [Sass] to take input files from
|
|
115
|
+
`_assets/styles/*.scss` and to produce output to `_tmp/site.css`. Then,
|
|
116
|
+
you use the `ministamp` tag to copy the file with a fingerprint to
|
|
117
|
+
Jekyll's site destination directory:
|
|
104
118
|
|
|
105
|
-
```
|
|
119
|
+
```liquid
|
|
106
120
|
<link rel="stylesheet" href="{{ site.baseurl }}/{% ministamp _tmp/site.css assets/site.css %}">
|
|
107
121
|
```
|
|
108
122
|
|
|
109
123
|
#### `ministamp` call syntax
|
|
110
124
|
|
|
111
|
-
The argument for `ministamp` tag must be in [YAML] syntax, and
|
|
112
|
-
the argument as YAML must result either in a String or a
|
|
113
|
-
saw previously was the argument being parsed as a String;
|
|
114
|
-
effectively a shorthand version of passing the argument as a Hash
|
|
115
|
-
certain keys. That is, in the following call:
|
|
125
|
+
The argument for the `ministamp` tag must be in [YAML] syntax, and
|
|
126
|
+
parsing the argument as YAML must result either in a String or a
|
|
127
|
+
Hash. What you saw previously was the argument being parsed as a String;
|
|
128
|
+
it's effectively a shorthand version of passing the argument as a Hash
|
|
129
|
+
with certain keys. That is, in the following call:
|
|
116
130
|
|
|
117
|
-
```
|
|
131
|
+
```liquid
|
|
118
132
|
{% ministamp _tmp/site.css assets/site.css %}
|
|
119
133
|
```
|
|
120
134
|
|
|
121
135
|
the argument is a String: `"_tmp/site.css assets/site.css"`. The call is
|
|
122
|
-
equivalent to the following call with Hash argument:
|
|
136
|
+
equivalent to the following call with a Hash argument:
|
|
123
137
|
|
|
124
|
-
```
|
|
138
|
+
```liquid
|
|
125
139
|
{% ministamp { source_path: _tmp/site.css, destination_path: assets/site.css } %}
|
|
126
140
|
```
|
|
127
141
|
|
|
@@ -130,18 +144,18 @@ The Hash argument allows expressing more options and quoting
|
|
|
130
144
|
|
|
131
145
|
The supported keys for the Hash argument are:
|
|
132
146
|
|
|
133
|
-
| Key
|
|
134
|
-
|
|
|
135
|
-
| `source_path`
|
|
136
|
-
| `destination_path`
|
|
137
|
-
| `render_basename_only` | no
|
|
147
|
+
| Key | Required? | Value type | Value example | Default value | Description |
|
|
148
|
+
| ---------------------- | --------- | ---------- | ------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
149
|
+
| `source_path` | yes | string | `'_tmp/site.css'` | - | The source path of the asset file, relative to the site directory. |
|
|
150
|
+
| `destination_path` | yes | string | `'assets/site.css'` | - | The destination path of the asset file, relative to Jekyll's site destination directory. If the value begins with `/` and `render_basename_only` is `false`, `ministamp`'s output will begin with `/`. |
|
|
151
|
+
| `render_basename_only` | no | boolean | `true` | `false` | If `true`, `ministamp`'s rendered URL will be the basename of the asset destination path. See [Separating asset destination path from generated URL](#separating-asset-destination-path-from-generated-url) for more. |
|
|
138
152
|
|
|
139
|
-
With Hash argument, the plugin processes `source_path` and
|
|
153
|
+
With a Hash argument, the plugin processes `source_path` and
|
|
140
154
|
`destination_path` values through a tiny template engine. This allows
|
|
141
155
|
you to use Liquid's variables as input to `ministamp` tag. An example
|
|
142
156
|
with Liquid's [`assign`][LiquidAssignTag] tag:
|
|
143
157
|
|
|
144
|
-
```
|
|
158
|
+
```liquid
|
|
145
159
|
{% assign asset_dir = 'assets' %}
|
|
146
160
|
<link rel="stylesheet" href="{% ministamp { source_path: _tmp/site.css, destination_path: '{{ asset_dir }}/site.css' } %}">
|
|
147
161
|
```
|
|
@@ -162,19 +176,19 @@ template syntax.
|
|
|
162
176
|
### Asset bundling
|
|
163
177
|
|
|
164
178
|
This is a straightforward way to bundle assets with any minification
|
|
165
|
-
tool that supports reading input from
|
|
166
|
-
|
|
179
|
+
tool that supports reading input from stdin and writing the output to
|
|
180
|
+
stdout. You write the configuration for input sources directly into the
|
|
167
181
|
content file where you want the markup tag for the bundle file to
|
|
168
182
|
appear. The markup tag contains the path to the bundle file, and the
|
|
169
183
|
Jekyll's site destination directory will have the bundle file at that
|
|
170
184
|
path. The path will contain an MD5 fingerprint.
|
|
171
185
|
|
|
172
|
-
Place `minibundle` [Liquid] block into the Liquid template file
|
|
173
|
-
you want the block's generated markup to appear. Write bundling
|
|
186
|
+
Place the `minibundle` [Liquid] block into the Liquid template file
|
|
187
|
+
where you want the block's generated markup to appear. Write bundling
|
|
174
188
|
configuration inside the block in [YAML] syntax. For example, to bundle
|
|
175
189
|
a set of JavaScript sources:
|
|
176
190
|
|
|
177
|
-
```
|
|
191
|
+
```text
|
|
178
192
|
{% minibundle js %}
|
|
179
193
|
source_dir: _assets/scripts
|
|
180
194
|
destination_path: assets/site
|
|
@@ -191,8 +205,8 @@ attributes:
|
|
|
191
205
|
Then, specify the command for launching your favorite minifier in
|
|
192
206
|
`_config.yml`:
|
|
193
207
|
|
|
194
|
-
```
|
|
195
|
-
baseurl:
|
|
208
|
+
```yaml
|
|
209
|
+
baseurl: ""
|
|
196
210
|
|
|
197
211
|
minibundle:
|
|
198
212
|
minifier_commands:
|
|
@@ -202,9 +216,9 @@ minibundle:
|
|
|
202
216
|
When it's time to render the `minibundle` block, the plugin launches the
|
|
203
217
|
minifier and connects to it with a Unix pipe. The plugin feeds the
|
|
204
218
|
contents of the asset files in `source_dir` directory as input to the
|
|
205
|
-
minifier (
|
|
219
|
+
minifier (stdin). The feeding order is the order of the files in the
|
|
206
220
|
`assets` key in the block configuration. The plugin expects the minifier
|
|
207
|
-
to produce output (
|
|
221
|
+
to produce output (stdout) and writes it to the file at
|
|
208
222
|
`destination_path` in Jekyll's site destination directory. The filename
|
|
209
223
|
will contain a fingerprint.
|
|
210
224
|
|
|
@@ -212,7 +226,7 @@ The block outputs `<link>` (for `css` type) or `<script>` (for `js`
|
|
|
212
226
|
type) HTML element into Liquid's template rendering outcome. Continuing
|
|
213
227
|
the example above, the block's output will be:
|
|
214
228
|
|
|
215
|
-
```
|
|
229
|
+
```html
|
|
216
230
|
<script src="/assets/site-8e764372a0dbd296033cb2a416f064b5.js" type="text/javascript" id="my-scripts" async></script>
|
|
217
231
|
```
|
|
218
232
|
|
|
@@ -222,13 +236,13 @@ above, to the generated markup with `attributes` map inside the
|
|
|
222
236
|
|
|
223
237
|
As shown above for the `baseurl` key, you can use Liquid template syntax
|
|
224
238
|
inside the contents of the block. Liquid renders block contents before
|
|
225
|
-
`minibundle` block gets the turn to render itself. Just ensure that
|
|
239
|
+
the `minibundle` block gets the turn to render itself. Just ensure that
|
|
226
240
|
block contents will result in valid YAML.
|
|
227
241
|
|
|
228
242
|
For bundling CSS assets, use `css` as the argument to the `minibundle`
|
|
229
243
|
block:
|
|
230
244
|
|
|
231
|
-
```
|
|
245
|
+
```text
|
|
232
246
|
{% minibundle css %}
|
|
233
247
|
source_dir: _assets/styles
|
|
234
248
|
destination_path: assets/site
|
|
@@ -243,7 +257,7 @@ attributes:
|
|
|
243
257
|
|
|
244
258
|
And then specify the minifier command in `_config.yml`:
|
|
245
259
|
|
|
246
|
-
```
|
|
260
|
+
```yaml
|
|
247
261
|
minibundle:
|
|
248
262
|
minifier_commands:
|
|
249
263
|
css: _bin/remove_whitespace
|
|
@@ -256,40 +270,40 @@ Use `css` or `js` as the argument to the opening tag, for example `{% minibundle
|
|
|
256
270
|
|
|
257
271
|
The block contents must be in [YAML] syntax. The supported keys are:
|
|
258
272
|
|
|
259
|
-
| Key
|
|
260
|
-
|
|
|
261
|
-
| `source_dir`
|
|
262
|
-
| `assets`
|
|
263
|
-
| `destination_path`
|
|
264
|
-
| `baseurl`
|
|
265
|
-
| `destination_baseurl` | string
|
|
266
|
-
| `attributes`
|
|
267
|
-
| `minifier_cmd`
|
|
273
|
+
| Key | Value type | Value example | Default value | Description |
|
|
274
|
+
| --------------------- | ---------------------------- | --------------------------------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
275
|
+
| `source_dir` | string | - | `'_assets'` | The source directory of `assets`, relative to the site directory. You can use period (`.`) to select the site directory itself. |
|
|
276
|
+
| `assets` | array of strings | `['deps/one', 'deps/two', 'app']` | `[]` | Array of assets relative to `source_dir` directory, without type extension. These are the asset files to be bundled, in order, into one bundle destination file. |
|
|
277
|
+
| `destination_path` | string | - | `'assets/site'` | The destination path of the bundle file, without type extension, relative to Jekyll's site destination directory. If the value begins with `/` and `baseurl` is empty, `baseurl` will be set to `'/'` implicitly. |
|
|
278
|
+
| `baseurl` | string | `'{{ site.baseurl }}/'` | `''` | If nonempty, the bundle destination URL inside `minibundle`'s rendered HTML element will be this value prepended to the destination path of the bundle file. Ignored if `destination_baseurl` is nonempty. |
|
|
279
|
+
| `destination_baseurl` | string | `'{{ site.cdn_baseurl }}/'` | `''` | If nonempty, the bundle destination URL inside `minibundle`'s rendered HTML element will be this value prepended to the basename of the bundle destination path. See [Separating asset destination path from generated URL](#separating-asset-destination-path-from-generated-url) for more. |
|
|
280
|
+
| `attributes` | map of keys to string values | `{id: my-link, media: screen}` | `{}` | Custom HTML element attributes to be added to `minibundle`'s rendered HTML element. |
|
|
281
|
+
| `minifier_cmd` | string | `'node_modules/.bin/uglifyjs'` | - | Minifier command specific to this bundle. See [Minifier command specification](#minifier-command-specification) for more. |
|
|
268
282
|
|
|
269
283
|
### Minifier command specification
|
|
270
284
|
|
|
271
285
|
You can specify minifier commands in three places:
|
|
272
286
|
|
|
273
|
-
1.
|
|
287
|
+
1. In `_config.yml` (as shown earlier):
|
|
274
288
|
|
|
275
|
-
```
|
|
289
|
+
```yaml
|
|
276
290
|
minibundle:
|
|
277
291
|
minifier_commands:
|
|
278
292
|
css: _bin/remove_whitespace
|
|
279
293
|
js: node_modules/.bin/uglifyjs
|
|
280
294
|
```
|
|
281
295
|
|
|
282
|
-
2.
|
|
296
|
+
2. As environment variables:
|
|
283
297
|
|
|
284
|
-
```
|
|
298
|
+
```bash
|
|
285
299
|
export JEKYLL_MINIBUNDLE_CMD_CSS=_bin/remove_whitespace
|
|
286
300
|
export JEKYLL_MINIBUNDLE_CMD_JS="node_modules/.bin/uglifyjs"
|
|
287
301
|
```
|
|
288
302
|
|
|
289
|
-
3.
|
|
303
|
+
3. Inside the `minibundle` block with `minifier_cmd` option, allowing
|
|
290
304
|
blocks to have different commands from each other:
|
|
291
305
|
|
|
292
|
-
```
|
|
306
|
+
```text
|
|
293
307
|
{% minibundle js %}
|
|
294
308
|
source_dir: _assets/scripts
|
|
295
309
|
destination_path: assets/site
|
|
@@ -304,8 +318,8 @@ You can specify minifier commands in three places:
|
|
|
304
318
|
|
|
305
319
|
These ways of specification are listed in increasing order of
|
|
306
320
|
specificity. Should multiple commands apply to a block, the most
|
|
307
|
-
specific one wins. For example, the `minifier_cmd` option inside `{%
|
|
308
|
-
minibundle js }%` block overrides the setting in
|
|
321
|
+
specific one wins. For example, the `minifier_cmd` option inside the `{%
|
|
322
|
+
minibundle js }%` block overrides the setting in the
|
|
309
323
|
`$JEKYLL_MINIBUNDLE_CMD_JS` environment variable.
|
|
310
324
|
|
|
311
325
|
### Recommended directory layout
|
|
@@ -317,7 +331,7 @@ site destination directory.
|
|
|
317
331
|
For example, in the following snippet we're using `assets/src.css` as
|
|
318
332
|
asset source to `ministamp` tag:
|
|
319
333
|
|
|
320
|
-
```
|
|
334
|
+
```liquid
|
|
321
335
|
<!-- BAD: unless assets dir is excluded, both src.css and dest.css will be copied to site destination directory -->
|
|
322
336
|
<link rel="stylesheet" href="{{ site.baseurl }}/{% ministamp assets/src.css assets/dest.css %}" media="screen, projection">
|
|
323
337
|
```
|
|
@@ -332,11 +346,11 @@ Because Jekyll's site generation excludes underscore directories (that
|
|
|
332
346
|
is, directories whose name begins with underscore character), consider
|
|
333
347
|
using the following directory layout:
|
|
334
348
|
|
|
335
|
-
|
|
349
|
+
- `_assets/` for JavaScript and CSS assets handled by the plugin that
|
|
336
350
|
are in version control
|
|
337
|
-
|
|
351
|
+
- `_tmp/` for temporary JavaScript and CSS assets handled by the plugin
|
|
338
352
|
that are not in version control (for example, Sass output files)
|
|
339
|
-
|
|
353
|
+
- `assets/` for images and other assets handled by Jekyll directly
|
|
340
354
|
|
|
341
355
|
However, Jekyll's watch mode (auto-regeneration) does monitor files
|
|
342
356
|
inside underscore directories. If such a file is modified, the watch
|
|
@@ -348,7 +362,7 @@ The `exclude` [Jekyll configuration][JekyllConf] option affects Jekyll's
|
|
|
348
362
|
watch mode. Given the recommended directory layout above, if you set the
|
|
349
363
|
following in `_config.yml`:
|
|
350
364
|
|
|
351
|
-
```
|
|
365
|
+
```yaml
|
|
352
366
|
exclude:
|
|
353
367
|
- _assets
|
|
354
368
|
- _tmp
|
|
@@ -356,7 +370,7 @@ exclude:
|
|
|
356
370
|
|
|
357
371
|
Then Jekyll won't see if files inside those directories have changed and
|
|
358
372
|
the plugin won't get the chance to update assets to the site destination
|
|
359
|
-
directory. So, don't explicitly exclude `_assets` and `_tmp`
|
|
373
|
+
directory. So, don't explicitly exclude the `_assets` and `_tmp`
|
|
360
374
|
directories.
|
|
361
375
|
|
|
362
376
|
See [Jekyll configuration][JekyllConf] for more about excluding files
|
|
@@ -364,22 +378,22 @@ and directories.
|
|
|
364
378
|
|
|
365
379
|
### Development mode
|
|
366
380
|
|
|
367
|
-
If you set `$JEKYLL_MINIBUNDLE_MODE` environment variable to
|
|
381
|
+
If you set the `$JEKYLL_MINIBUNDLE_MODE` environment variable to
|
|
368
382
|
`development`, then the plugin will copy asset files as is to Jekyll's
|
|
369
383
|
site destination directory and omit fingerprinting.
|
|
370
384
|
|
|
371
385
|
The development mode changes `minibundle` block's `destination_path`
|
|
372
|
-
option to be the base directory for files mentioned in `assets`
|
|
386
|
+
option to be the base directory for files mentioned in the `assets`
|
|
373
387
|
option. This is useful in development workflow, where you need the
|
|
374
388
|
filenames and line numbers of the original asset sources.
|
|
375
389
|
|
|
376
|
-
```
|
|
390
|
+
```bash
|
|
377
391
|
$ JEKYLL_MINIBUNDLE_MODE=development jekyll serve --watch
|
|
378
392
|
```
|
|
379
393
|
|
|
380
394
|
Alternatively, you can enable development mode from `_config.yml`:
|
|
381
395
|
|
|
382
|
-
```
|
|
396
|
+
```yaml
|
|
383
397
|
minibundle:
|
|
384
398
|
mode: development
|
|
385
399
|
```
|
|
@@ -416,21 +430,21 @@ named `nosuch`.
|
|
|
416
430
|
|
|
417
431
|
### Separating asset destination path from generated URL
|
|
418
432
|
|
|
419
|
-
Use `render_basename_only: true` option of `ministamp` tag and
|
|
420
|
-
`destination_baseurl` option of `minibundle` block to separate
|
|
421
|
-
destination path of the asset file from the generated URL of the
|
|
433
|
+
Use the `render_basename_only: true` option of the `ministamp` tag and
|
|
434
|
+
the `destination_baseurl` option of the `minibundle` block to separate
|
|
435
|
+
the destination path of the asset file from the generated URL of the
|
|
422
436
|
asset. This allows you to serve the asset from a separate domain, for
|
|
423
437
|
example.
|
|
424
438
|
|
|
425
439
|
Example usage, with the following content in `_config.yml`:
|
|
426
440
|
|
|
427
|
-
```
|
|
428
|
-
cdn_baseurl:
|
|
441
|
+
```yaml
|
|
442
|
+
cdn_baseurl: "https://cdn.example.com"
|
|
429
443
|
```
|
|
430
444
|
|
|
431
|
-
For `ministamp` tag:
|
|
445
|
+
For the `ministamp` tag:
|
|
432
446
|
|
|
433
|
-
```
|
|
447
|
+
```liquid
|
|
434
448
|
<link rel="stylesheet" href="{{ site.cdn_baseurl }}/css/{% ministamp { source_path: '_tmp/site.css', destination_path: assets/site.css, render_basename_only: true } %}">
|
|
435
449
|
```
|
|
436
450
|
|
|
@@ -438,13 +452,13 @@ The asset file will be in Jekyll's site destination directory with path
|
|
|
438
452
|
`assets/site-ff9c63f843b11f9c3666fe46caaddea8.css`, and Liquid's
|
|
439
453
|
rendering will result in:
|
|
440
454
|
|
|
441
|
-
```
|
|
442
|
-
<link rel="stylesheet" href="https://cdn.example.com/css/site-ff9c63f843b11f9c3666fe46caaddea8.css"
|
|
455
|
+
```html
|
|
456
|
+
<link rel="stylesheet" href="https://cdn.example.com/css/site-ff9c63f843b11f9c3666fe46caaddea8.css" />
|
|
443
457
|
```
|
|
444
458
|
|
|
445
|
-
For `minibundle` block:
|
|
459
|
+
For the `minibundle` block:
|
|
446
460
|
|
|
447
|
-
```
|
|
461
|
+
```liquid
|
|
448
462
|
{% minibundle js %}
|
|
449
463
|
source_dir: _assets/scripts
|
|
450
464
|
destination_path: assets/site
|
|
@@ -459,7 +473,7 @@ The bundle file will be in Jekyll's site destination directory with path
|
|
|
459
473
|
`assets/site-4782a1f67803038d4f8351051e67deb8.js`, and Liquid's
|
|
460
474
|
rendering will result in:
|
|
461
475
|
|
|
462
|
-
```
|
|
476
|
+
```html
|
|
463
477
|
<script type="text/javascript" src="https://cdn.example.com/js/site-4782a1f67803038d4f8351051e67deb8.js"></script>
|
|
464
478
|
```
|
|
465
479
|
|
|
@@ -471,15 +485,15 @@ process the string as you like.
|
|
|
471
485
|
|
|
472
486
|
For example:
|
|
473
487
|
|
|
474
|
-
```
|
|
488
|
+
```liquid
|
|
475
489
|
{% capture site_css %}{% ministamp _assets/site.css assets/site.css %}{% endcapture %}
|
|
476
490
|
<link rel="stylesheet" href="{{ site_css | remove_first: "assets/" }}">
|
|
477
491
|
```
|
|
478
492
|
|
|
479
493
|
Liquid's rendering outcome:
|
|
480
494
|
|
|
481
|
-
```
|
|
482
|
-
<link rel="stylesheet" href="site-390be921ee0eff063817bb5ef2954300.css"
|
|
495
|
+
```html
|
|
496
|
+
<link rel="stylesheet" href="site-390be921ee0eff063817bb5ef2954300.css" />
|
|
483
497
|
```
|
|
484
498
|
|
|
485
499
|
## Example site
|
|
@@ -496,8 +510,10 @@ The plugin does not work with Jekyll's incremental rebuild feature
|
|
|
496
510
|
MIT. See [LICENSE.txt].
|
|
497
511
|
|
|
498
512
|
[Gemfile]: https://bundler.io/gemfile.html
|
|
499
|
-
[
|
|
513
|
+
[GoogleWebDevHttpCache]: https://web.dev/http-cache/
|
|
514
|
+
[JekyllBuiltInAssets]: https://jekyllrb.com/docs/assets/
|
|
500
515
|
[JekyllConf]: https://jekyllrb.com/docs/configuration/
|
|
516
|
+
[JekyllLiquidFilters]: https://jekyllrb.com/docs/liquid/filters/
|
|
501
517
|
[JekyllMinibundleExampleSite]: https://github.com/tkareine/jekyll-minibundle-example
|
|
502
518
|
[Jekyll]: https://jekyllrb.com/
|
|
503
519
|
[LICENSE.txt]: https://raw.githubusercontent.com/tkareine/jekyll-minibundle/master/LICENSE.txt
|
|
@@ -505,7 +521,7 @@ MIT. See [LICENSE.txt].
|
|
|
505
521
|
[LiquidCaptureBlock]: https://shopify.github.io/liquid/tags/variable/#capture
|
|
506
522
|
[Liquid]: https://shopify.github.io/liquid/
|
|
507
523
|
[MD5]: https://en.wikipedia.org/wiki/MD5
|
|
508
|
-
[MinibundleCI]: https://github.com/tkareine/jekyll-minibundle/actions
|
|
524
|
+
[MinibundleCI]: https://github.com/tkareine/jekyll-minibundle/actions/workflows/ci.yml
|
|
509
525
|
[MinibundleGem]: https://rubygems.org/gems/jekyll-minibundle
|
|
510
526
|
[Mustache]: https://mustache.github.io/
|
|
511
527
|
[Sass]: https://sass-lang.com/
|
data/Rakefile
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'bundler/gem_helper'
|
|
3
4
|
require 'fileutils'
|
|
4
5
|
require 'rake/clean'
|
|
5
6
|
require 'shellwords'
|
|
@@ -11,11 +12,11 @@ def run_jekyll_in_fixture_site(command)
|
|
|
11
12
|
Dir.chdir('test/fixture/site')
|
|
12
13
|
FileUtils.rm_rf('_site')
|
|
13
14
|
|
|
14
|
-
minifier_cmd = File.expand_path(
|
|
15
|
+
minifier_cmd = File.expand_path('test/fixture/site/_bin/remove_comments', File.dirname(__FILE__))
|
|
15
16
|
env = {
|
|
16
17
|
'JEKYLL_MINIBUNDLE_CMD_JS' => minifier_cmd,
|
|
17
18
|
'JEKYLL_MINIBUNDLE_CMD_CSS' => minifier_cmd,
|
|
18
|
-
'RUBYLIB' => File.expand_path(File.
|
|
19
|
+
'RUBYLIB' => File.expand_path('lib', File.dirname(__FILE__))
|
|
19
20
|
}
|
|
20
21
|
jekyll_cmd = "jekyll #{command}"
|
|
21
22
|
|
|
@@ -32,7 +33,7 @@ task :benchmark do
|
|
|
32
33
|
|
|
33
34
|
bm_sources =
|
|
34
35
|
if run_single_bm
|
|
35
|
-
[ENV
|
|
36
|
+
[ENV.fetch('BM')]
|
|
36
37
|
else
|
|
37
38
|
Dir['benchmark/*_bm.rb']
|
|
38
39
|
end
|
|
@@ -42,27 +43,6 @@ task :benchmark do
|
|
|
42
43
|
end
|
|
43
44
|
end
|
|
44
45
|
|
|
45
|
-
namespace :gem do
|
|
46
|
-
gem_name = 'jekyll-minibundle'
|
|
47
|
-
|
|
48
|
-
CLEAN.include "#{gem_name}-*.gem"
|
|
49
|
-
|
|
50
|
-
desc 'Package the software as a gem'
|
|
51
|
-
task build: :default do
|
|
52
|
-
sh "gem build #{gem_name}.gemspec"
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
desc 'Install the software as a gem'
|
|
56
|
-
task :install do
|
|
57
|
-
sh "gem install #{gem_name}-#{Jekyll::Minibundle::VERSION}.gem"
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
desc 'Uninstall the gem'
|
|
61
|
-
task uninstall: :clean do
|
|
62
|
-
sh "gem uninstall #{gem_name}"
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
46
|
desc <<~TEXT
|
|
67
47
|
Run tests. Supported options from environment variables:
|
|
68
48
|
|
|
@@ -76,7 +56,7 @@ task :test do
|
|
|
76
56
|
run_selected_or_all =
|
|
77
57
|
if ENV.key?('TEST')
|
|
78
58
|
test_file = ENV['TEST']
|
|
79
|
-
minitest_opts = "#{
|
|
59
|
+
minitest_opts = "#{"-n #{ENV['NAME']} " if ENV.key?('NAME')}#{ENV.fetch('TEST_OPTS', '')}"
|
|
80
60
|
"#{test_file} #{minitest_opts}"
|
|
81
61
|
else
|
|
82
62
|
eval = "-e 'ARGV.each { |f| require \"#{Dir.pwd}/test/\#{f}\" }'"
|
|
@@ -87,7 +67,7 @@ task :test do
|
|
|
87
67
|
"#{eval} #{requirable_files}"
|
|
88
68
|
end
|
|
89
69
|
|
|
90
|
-
ruby_opts = "-I lib#{
|
|
70
|
+
ruby_opts = "-I lib#{' -w -rpp -rpry' if ENV['DEBUG']}"
|
|
91
71
|
|
|
92
72
|
puts "Jekyll version: #{Gem::Specification.find_by_name('jekyll').version}"
|
|
93
73
|
sh "ruby #{ruby_opts} #{run_selected_or_all}"
|
|
@@ -107,6 +87,8 @@ namespace :fixture do
|
|
|
107
87
|
end
|
|
108
88
|
end
|
|
109
89
|
|
|
90
|
+
Bundler::GemHelper.install_tasks
|
|
91
|
+
|
|
110
92
|
RuboCop::RakeTask.new
|
|
111
93
|
|
|
112
94
|
task default: %i[rubocop test]
|
data/jekyll-minibundle.gemspec
CHANGED
|
@@ -19,6 +19,10 @@ Gem::Specification.new do |s|
|
|
|
19
19
|
(not even other gems).
|
|
20
20
|
TEXT
|
|
21
21
|
|
|
22
|
+
s.metadata = {
|
|
23
|
+
'rubygems_mfa_required' => 'true'
|
|
24
|
+
}
|
|
25
|
+
|
|
22
26
|
s.files = %w[
|
|
23
27
|
CHANGELOG.md
|
|
24
28
|
LICENSE.txt
|
|
@@ -27,17 +31,7 @@ Gem::Specification.new do |s|
|
|
|
27
31
|
jekyll-minibundle.gemspec
|
|
28
32
|
] + `git ls-files -- lib`.split("\n")
|
|
29
33
|
|
|
30
|
-
s.
|
|
31
|
-
|
|
32
|
-
s.add_development_dependency 'benchmark-ips', '~> 2.7'
|
|
33
|
-
s.add_development_dependency 'jekyll', '>= 3.0'
|
|
34
|
-
s.add_development_dependency 'minitest', '~> 5.8'
|
|
35
|
-
s.add_development_dependency 'nokogiri', '~> 1.6'
|
|
36
|
-
s.add_development_dependency 'pry', '~> 0.10'
|
|
37
|
-
s.add_development_dependency 'rake', '~> 13.0'
|
|
38
|
-
s.add_development_dependency 'rubocop', '~> 0.90.0'
|
|
39
|
-
|
|
40
|
-
s.required_ruby_version = '>= 2.4.0'
|
|
34
|
+
s.required_ruby_version = '>= 2.7.0'
|
|
41
35
|
|
|
42
36
|
s.rdoc_options << '--line-numbers' << '--title' << s.name << '--exclude' << 'test'
|
|
43
37
|
end
|
|
@@ -47,7 +47,7 @@ module Jekyll::Minibundle
|
|
|
47
47
|
Log.info("Bundling #{bundle_destination_path}:")
|
|
48
48
|
@asset_paths.each do |asset|
|
|
49
49
|
Log.info(" #{relative_path_from(asset, @site_dir)}")
|
|
50
|
-
|
|
50
|
+
File.foreach(asset) { |line| input.write(line) }
|
|
51
51
|
input.puts(';') if @type == :js
|
|
52
52
|
end
|
|
53
53
|
end
|
|
@@ -137,6 +137,6 @@ module Jekyll::Minibundle
|
|
|
137
137
|
end
|
|
138
138
|
end
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
Jekyll::Hooks.register(:site, :post_write) do
|
|
141
|
+
Jekyll::Minibundle::AssetFileRegistry.clear_unused
|
|
142
142
|
end
|
|
@@ -19,7 +19,7 @@ module Jekyll::Minibundle
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def self.make_attributes(attributes)
|
|
22
|
-
attributes.map { |name, value| make_attribute(name, value) }.join
|
|
22
|
+
attributes.map { |name, value| make_attribute(name, value) }.join
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def self.make_attribute(name, value)
|