A JavaScript converter for Jekyll. JavaScript files can be concatenated using special comments and then minified using Uglifier.
Add the gem to the jekyll_plugins
group in the site's Gemfile:
group :jekyll_plugins do
gem 'jekyll-js-converter'
end
And then bundle:
$ bundle
Add front matter to the JavaScript files which jekyll-js-converter needs to convert (e.g. the main JavaScript file for the site like assets/js/my-site.js
). Three directives can then be used to add the contents of other JavaScript files to the file being converted. Note that these other files can use the directives too, but do not need front matter however (think of them as "partials").
---
---
//= import <SOME_FILE>
//= import_directory <SOME_DIRECTORY>
//= import_tree <SOME_DIRECTORY>
console.log('This file has been converted by jekyll-js-converter!')
By default, jekyll-js-converter will look for the files and directories to import in the site's _javascript
folder as well as the theme's _javascript
folder (if one is present). It can also be configured with additional load paths as well (see Configuration).
import
adds the contents of the given file (either a local file or a URI)import_directory
adds the contents of each.js
file in the given directoryimport_tree
adds the contents of all.js
files in all directories of the given directory
Configuration options are added to the _config.yml
file like this:
javascript:
...
The options are:
The path (relative to the site's source
option) of the directory which contains the JavaScript "partials".
Defaults to _javascript
.
Additional paths (relative to the site's source
option) to search for JavaScript "partials" in. These should be given as an array.
Defaults to []
.
Whether a .map.js
file should be created or not. Valid values are:
always
: map files will be creatednever
: no map files will be createddevelopment
: map files will be created if the site is generated withJEKYLL_ENV='development'
Defaults to always
.
Options to pass to Uglifier.new
which is then used to compile the JavaScript.
Defaults to {}
.
- Fork
https://github.com/dsusco/jekyll-js-converter
- Create a branch (
git checkout -b new-feature
) - Commit the changes (
git commit -am 'Added a new feature'
) - Push the branch (
git push origin new-feature
) - Create a pull request