How to use the rework function in rework

To help you get started, we’ve selected a few rework examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dustinspecker / gulp-modify-css-urls / src / index.js View on Github external
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()
github purifycss / purifycss / src / CssTreeWalker.js View on Github external
beginReading() {
        this.ast = rework(this.startingSource).use(this.readPlugin.bind(this))
    }
github gnandretta / babel-plugin-transform-css-import-to-string / src / index.js View on Github external
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))]));
          }
        }
      }
github purifycss / purifycss / lib / purifycss.es.js View on Github external
value: function beginReading() {
            this.ast = rework(this.startingSource).use(this.readPlugin.bind(this));
        }
    }, {