Skip to content

Instantly share code, notes, and snippets.

@fourjuaneight
Created July 29, 2019 22:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fourjuaneight/5c0981aa7b97d55fe159db55a822cf07 to your computer and use it in GitHub Desktop.
Save fourjuaneight/5c0981aa7b97d55fe159db55a822cf07 to your computer and use it in GitHub Desktop.
Babel + Terser 11ty Pipeline
const { readFileSync } = require('fs');
const babel = require('@babel/core');
const Terser = require('terser');
// file paths
const color = readFileSync('assets/js/color.js', 'utf8', data => data);
const noise = readFileSync('assets/js/noise.js', 'utf8', data => data);
const outputFile = 'scripts.js';
module.exports = class {
data() {
return {
eleventyExcludeFromCollections: true,
layout: false,
permalink: outputFile,
};
}
async render() {
const compiled = await babel
.transformAsync(`${color}${noise}`)
.then(result => result.code);
const minified = await Terser.minify(compiled);
return minified.code;
}
};
@liamfiddler
Copy link

Love it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment