Giter VIP home page Giter VIP logo

jekyll-plugin-frontend-build's Introduction

Jekyll frontend build plugin

This is a very minimal plugin that post-processes front-end assets, enabling you to use the latest ES features with fewer worries about cross-browser compatibility.

This plugin depends on Node/NPM and currently uses Babel.

The plugin uses the “assets” directory in site source as input, and _site/assets as output.

Current limitations:

  • As of now, it only processes JavaScript files under assets/js with Babel.

Caveats:

  • You may need to include Babel’s polyfill script explicitly.

Roadmap:

  • Post-process the CSS with at least auto-prefixer (#2)

  • Combine front-end assets into a few packages (bulk of JS, bulk of CSS) and minify it (#3)

  • Make source asset directory (directories) configurable

  • (?) Use Web components, e.g. Polymer

Requirements

This plugin requires Node & NPM to be available in Jekyll build environment.

Setting up

A quick way to use this plugin with a new site is to use the Jekyll site template.

Alternatively, to add this plugin to an existing site, create the following files in your site root, and run npm install afterwards:

package.json
{
  "version": "1.0.0",
  "main": "babel.config.js",
  "dependencies": {
    "@babel/cli": "^7.5.5",
    "@babel/core": "^7.5.5",
    "@babel/polyfill": "^7.4.4",
    "@babel/preset-env": "^7.5.5"
  }
}
babel.config.js
const presets = [
  [
    "@babel/env",
    {
      targets: {
        ie: "10",
        edge: "17",
        firefox: "60",
        chrome: "67",
        safari: "11.1",
      },
    },
  ],
];

module.exports = { presets };

Using during development

The plugin will take effect if you run jekyll serve as usual.

Using in production/CI

Just make sure that Node/NPM are available in your environment, and call npm install before building the site.

See .travis.yml in https://github.com/riboseinc/jekyll-site-skeleton for an example.

Including Babel polyfill

For certain functionality, Babel requires a polyfill script to be executed before your code.

The plugin copies the pollyfill under _site/assets/js, so including it isn’t difficult.

  • To include Babel polyfill in normal browser window context:

    <script src="/assets/js/babel-polyfill.js"></script>
  • To include Babel polyfill in Web worker context:

    importScripts('/assets/js/babel-polyfill.js');
    
    // The rest of the code

Troubleshooting

ReferenceError: regeneratorRuntime is not defined

This might happen in worker context.

Solution: include Babel polyfill before your code (see the Including Babel polyfill section).

Symbol or Symbol.iterator is not defined

This might happen in browser window context.

Solution: include Babel polyfill before your code (see the Including Babel polyfill section).

jekyll-plugin-frontend-build's People

Contributors

strogonoff avatar

Watchers

Ronald Tse avatar Sebastian Skałacki avatar  avatar Oleksii Kuznietsov avatar James Cloos avatar Bohdan Kalynovskyi (Dan) avatar Nick Nicholas avatar  avatar KW Kwan avatar  avatar

Forkers

skalee

jekyll-plugin-frontend-build's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.