Skip to content

Instantly share code, notes, and snippets.

@hugosenari
Created March 13, 2020 01:22
Show Gist options
  • Save hugosenari/a6e91b80172677f318d90d6c8799e7ec to your computer and use it in GitHub Desktop.
Save hugosenari/a6e91b80172677f318d90d6c8799e7ec to your computer and use it in GitHub Desktop.
Sapper postbuild Gulpfile
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