Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const modifyUrls = (filePath, fileContents, sourcemap, options = {}) => {
const {append, modify, prepend} = options
return rework(fileContents, {source: filePath})
.use(reworkFunc({
url(url) {
/**
* The split/join/trim logic is copied from rework-plugin-url to remove redundant quotes.
* Currently removed due to: https://github.com/reworkcss/rework-plugin-url/issues/7
*/
if (url.indexOf('data:') === 0) {
return `url("${url}")`
}
let formattedUrl = url
.split('"')
.join('')
.split('\'')
.join('')
.trim()
beginReading() {
this.ast = rework(this.startingSource).use(this.readPlugin.bind(this))
}
exit: function(path, state) {
const node = path.node;
if (endsWith(node.source.value, '.css')) {
const dir = p.dirname(p.resolve(state.file.opts.filename));
const absolutePath = p.resolve(dir, node.source.value);
const css = rework(fs.readFileSync(absolutePath, "utf8"))
.use(reworkImport({path: p.dirname(absolutePath)}))
.toString({compress: true});
path.replaceWith(t.variableDeclaration("var", [
t.variableDeclarator(
t.identifier(node.specifiers[0].local.name),
t.stringLiteral(css))]));
}
}
}
value: function beginReading() {
this.ast = rework(this.startingSource).use(this.readPlugin.bind(this));
}
}, {