Jekyll plugin that minifies JavaScript files with Terser after the site is written.
- Minifies all
.jsfiles from a configurable source directory. - Writes minified output into a configurable destination directory.
- Generates source maps by default.
- Falls back to copying the original file if minification fails.
- Ruby 3.1+
- Jekyll 4.4+
Add the gem to your Jekyll site's Gemfile:
gem 'jekyll-minify-js'Then install dependencies:
bundle installAdd a minify_js section to _config.yml:
minify_js:
enable: true
entry_dir: js
output_dir: js
compress: true
mangle: true
source_map: true| Option | Type | Default | Description |
|---|---|---|---|
enable |
boolean | true |
Set to false to skip minification. |
entry_dir |
string | js |
Directory inside your source site containing input JavaScript files. |
output_dir |
string | js |
Directory inside _site where minified files are written. |
compress |
boolean | true |
Enables Terser compression. |
mangle |
boolean | true |
Enables Terser name mangling. |
source_map |
boolean | true |
Generates .map files and appends sourceMappingURL. |
During Jekyll's post_write hook, the plugin:
- Reads JavaScript files from
entry_dir. - Minifies each file with Terser.
- Writes the result to
_site/output_dir. - Writes a source map when
source_mapis enabled. - Copies the original file if Terser raises an error for that file.
Directory structure example:
your-site/
js/
app.js
vendor/
search.js
_site/
js/
app.js
app.js.map
vendor/
search.js
search.js.map
If your source files live in assets/js and you want output in assets/js inside _site:
minify_js:
entry_dir: assets/js
output_dir: assets/js
compress: true
mangle: true
source_map: trueInstall dependencies:
bundle installRun checks:
bundle exec rubocopReleased under the MIT License. See LICENSE.txt.
