Created
August 16, 2017 05:19
-
-
Save arlair/b4417f2aa59410c4bac8b9192de12945 to your computer and use it in GitHub Desktop.
inlineCSS.js modifications from Serverless version
This file contains 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 path = require('path') | |
const fs = require('fs-extra') | |
const critical = require('critical') | |
const dir = require('node-dir') | |
// const distPath = path.join(__dirname, '..', '..', 'dist') | |
const firstArg = process.argv.slice(2)[0]; | |
// path comes back to root, appends dist folder | |
var distPath = path.join(__dirname, '..', '..', firstArg, 'dist'); | |
console.info('distPath: ' + distPath) | |
function inlineCSS(filePath, callBack) { | |
console.time('inlineCSS') | |
dir.readFiles(filePath, { | |
// match: /.html$/, | |
// 404.html was writing into root index.html, ignore 404 for now | |
match: /index.html$/, | |
//exclude: /^\./ | |
}, (err, content, filename, next) => { | |
if (err) throw err | |
console.log('filename', filename) | |
const directoryPath = path.dirname(filename) | |
const newPath = path.join(directoryPath, 'index.html') | |
// const newPath = path.join(directoryPath, 'index-critical.html') | |
console.log('newPath', newPath) | |
critical.generate({ | |
inline: true, | |
base: filePath, | |
src: filename, | |
dest: newPath, | |
minify: true, | |
dimensions: [{ | |
height: 200, | |
width: 500 | |
}, { | |
height: 900, | |
width: 1200 | |
}] | |
}, (err, output) => { | |
// console.log(output) | |
}) | |
next() | |
}, | |
(err, files) => { | |
if (err) { | |
if (callBack) { | |
callBack(err) | |
} | |
} | |
if (callBack) { | |
callBack(null, files) | |
} | |
console.log('files', files) | |
console.timeEnd('inlineCSS') | |
} | |
) | |
} | |
inlineCSS(distPath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapted from https://github.com/serverless/site/blob/6c6648a15dedca3c8c468115d8707c74b53edd99/scripts/build/inlineCSS.js
Not much difference: