Last active
July 25, 2018 09:48
-
-
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
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
{ | |
"name": "stylus-staticify", | |
"version": "0.1.0", | |
"main": "stylus-staticify.js", | |
"peerDependencies": { | |
"staticify": "^3.0.0", | |
} | |
} |
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
/* | |
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