How to use the rework.url 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 sergeche / grunt-frontend / tasks / lib / css.js View on Github external
var grunt = env.grunt;
		var imported = [];
		var style = rework(inlineImports.read(file.absPath));

		grunt.verbose.writeln('');

		if (config.inline) {
			grunt.verbose.writeln('Inlining ' + file.catalogPath.cyan);
			style.use(inlineImports(config.srcWebroot, file.absPath, imported));
		}

		if (config.rewriteUrl) {
			grunt.verbose.writeln('Rewriting URLs in ' + file.catalogPath.cyan);
			// rewrite urls to external resources
			style.use(rework.url(function(url) {
				return rewriteUrl(url, file, config);
			}));
		}

		var out = style.toString();

		if (config.minify) {
			// minify CSS
			grunt.verbose.writeln('Minifying ' + file.catalogPath.cyan);
			out = csso.justDoIt(out, true);
		}

		if (config.postProcess) {
			// do additional postprocessing, if required
			grunt.verbose.writeln('Postprocessing ' + file.catalogPath.cyan);
			out = config.postProcess(out, file);
github yuguo / gulp-import-css / index.js View on Github external
preProcess: function(ast, options) {
            return ast
                .use(rework.url(function(url) {
                    var srcDir,
                      resourcePath,
                      destDir;

                    if (isAbsoluteUrl(url) || isRootRelativeUrl(url)) {
                      return url;
                    }

                    // rebase relative url(...) found in CSS to be imported
                    // @import url(...) handled by rework-importer; not passed through here

                    srcDir = path.dirname(options.path);
                    resourcePath = path.resolve(srcDir, url);
                    destDir = path.dirname(file.path);

                    return path.relative(destDir, resourcePath);
github topcoat / resin / index.js View on Github external
}

    output = rework(read(src, 'utf8'));
    output.use(imprt());
    if(useVars) {
      output.use(vars());
    }
    output.use(dedupe());
    if(useExtend) {
      output.use(inherit());
    }
    if(namespace) {
      output.use(namespace(ns));
    }
    if(urlString) {
      output.use(rework.url(function(url) {
        return urlString + url;
      }));
    }
    output.use(autoprefixer(browsers).rework);
    output = output.toString({sourcemap: debug})
      .replace(/(\/\*\*[\s\S]*?(license)[\s\S]*?\*\/)([\s\t]*(\r\n|\n|\r))/gi, '');

    if(license) {
      if(exists(license)) {
        output = read(license) + output;
      } else {
        throw new Error("Sorry, I couldn't find the license file. Make sure you supply a valid path.");
      }
    }

    return output;
github kimjoar / gulp-css-rebase-urls / index.js View on Github external
var rebaseUrls = function(css, options) {
    return rework(css)
        .use(rework.url(function(url){
            if (isAbsolute(url) && validator.isURL(url)) {
                return url;
            }
            var absolutePath = path.join(options.currentDir, url)
            var p = path.relative(options.root, absolutePath);

            if (process.platform === 'win32') {
                p = p.replace(/\\/g, '/');
            }

            return p;
        }))
        .toString();
};
github jankuca / ng-scroller / build / css.task.js View on Github external
var css_part_code = fs.readFileSync(filename, 'utf8');
          var css_part = rework(css_part_code);

          var filename_rel_to_target = path.relative(
            path.dirname(target_filename),
            path.dirname(filename)
          );

          var fixUrl = function (url) {
            if (url[0] === '.') {
              var url_rel_to_target = path.join(filename_rel_to_target, url);
              return url_rel_to_target;
            }
            return url;
          };
          css_part.use(rework.url(fixUrl));

          css_code += css_part.toString();
        });