Created
July 29, 2019 22:38
-
-
Save fourjuaneight/5c0981aa7b97d55fe159db55a822cf07 to your computer and use it in GitHub Desktop.
Babel + Terser 11ty Pipeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Love it!