Skip to content

Instantly share code, notes, and snippets.

@Driptap
Last active July 25, 2018 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Driptap/9fc3e3b3685c34c5625775fe437951be to your computer and use it in GitHub Desktop.
Save Driptap/9fc3e3b3685c34c5625775fe437951be to your computer and use it in GitHub Desktop.
Simple stylus plugin that uses Staticfy replace paths to replace static asset paths in compiled css
{
"name": "stylus-staticify",
"version": "0.1.0",
"main": "stylus-staticify.js",
"peerDependencies": {
"staticify": "^3.0.0",
}
}
/*
Simple Stylus plugin that replaces paths with staticify paths.
*/
let staticify;
try {
staticify = require('staticify');
} catch (err) {
throw new Error('Staticify could not be found, please install it');
}
const DEFAULT_CONFIG_PATH = './config.staticify.js';
module.exports = function (opts) {
let config, configFilePath = DEFAULT_CONFIG_PATH;
if ('configFile' in opts)
configFilePath = opts.configFile;
try {
config = require(configFilePath);
} catch (err) {
throw new Error(
'Staticify config file not found at '
+ configFilePath
+ ', please specifiy one');
return;
}
if (!('root' in config) || !('options' in config))
throw new Error('Staticify config file is not correctly defined, ensure it is exporting a root and options variable');
const replacePaths = staticify(config.root, config.options).replacePaths;
return function (style) {
style.on('end', function (err, css) {
return replacePaths(css)
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment