Created
March 13, 2020 01:22
-
-
Save hugosenari/a6e91b80172677f318d90d6c8799e7ec to your computer and use it in GitHub Desktop.
Sapper postbuild Gulpfile
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 tap = require('gulp-tap'); | |
const postHTML = require('posthtml'); | |
const { series, src, dest } = require('gulp'); | |
const StreamFromPromise = require('stream-from-promise'); | |
const { exec } = require('child_process'); | |
const GLOB = './__sapper__/export/**/*.*'; | |
const DEST = './__sapper__/rexport/'; | |
const filter = (expr, cb) => file => expr.exec(file.path) && cb(file); | |
const runPostHtml = async file => { | |
const { path, contents } = file; | |
file.contents = StreamFromPromise( | |
postHTML([ | |
// posthtml plugins goes here | |
]) | |
.process(contents) | |
.then(({ html }) => html) | |
); | |
}; | |
const sapper = () => exec('sapper export --legacy'); | |
exports.default = series( | |
sapper, | |
function html() { | |
return src(GLOB) | |
.pipe(tap(filter(/\.html?$/, runPostHtml))) | |
.pipe(dest(DEST)); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment