Пример #1
0
/* Compiles the given CSS string using rework. */
function compile(string) {
  var css = rework(string)
    .use(reworkImport({
      path: 'src/components'
    }))
    .use(reworkVars())
    .toString({
      compress: true
    });
  return css;
}
Пример #2
0
read(options.input, function(err, buffer) {
  if (err) {
    console.error(err);
    console.error(err.stack);
  }
  var css = buffer.toString();

  css = rework(css, { source: options.input })
    .use(reworkImport())
    .use(reworkVars())
    .toString();

  css = autoprefixer.process(css);

  write(options.output, css);
});
Пример #3
0
gulp.task('buildcss', function () {
    return gulp.src('./css/style.css')
        .pipe(rework(reworkNPM({ 
            shim: { 
                'purecss': 'build/pure.css'
            }}),
            vars(), 
            inherit(),
            imprt({
                path: './css/modules/'
            })
            )
        )
        .pipe(autoprefixer({
            browsers: ['last 2 versions'],
            cascade: false
        }))
        .pipe(gulp.dest('public/css/'));
});
Пример #4
0
exports.import = function(options){
  return 'undefined' == typeof window && options.source
    ? importer()
    : function(){};
};
Пример #5
0
exports.processModule = function(descriptor, options, callback) {

	if (descriptor.errors.length > 0) {
		descriptor.errors.forEach(function(error) {
			console.error("ERROR", error, new Error().stack);
		});
		return callback(new Error("We had errors in descriptor for '" + options._realpath(descriptor.descriptor.filepath) + "'!"));
	}
//console.log("descriptor", descriptor);

	if (
		options.requireContext &&
		options.requireContext.plugin &&
		options.plugins &&
		options.plugins.require
	) {
		if (!options.plugins.require[options.requireContext.plugin]) {
			console.error("options.plugins.require", options.plugins.require);
			return callback(new Error("require plugin '" + options.requireContext.plugin + "' used in module '" + options._realpath(descriptor.descriptor.filepath) + "' but not declared in bundler config!"));
		}
		try {

			descriptor.variation = options.requireContext.plugin;

			return options.plugins.require[options.requireContext.plugin]["#pinf-it-bundler"].process(descriptor.descriptor, callback);

		} catch (err) {
			console.error(err.stack);
			return callback(new Error("Error while calling require transform plugin '" + options.requireContext.plugin + "'"));
		}
	}

	if (descriptor.descriptor.format === "scss") {

		return SASS.render({
			  file: options._realpath(descriptor.descriptor.filepath),
		    data: descriptor.descriptor.code,
		    includePaths: [
		    		options._realpath(options.packageExtras.packagePath)
		    ]
		}, function (err, result) {
				if (err) {
						console.error("message", err.message);
						console.error("code", err.code);
						console.error("line", err.line);
						console.error("column", err.column);
						return callback(new Error("SASS error while processing: " + descriptor.descriptor.filepath));
				}

//		        console.log(result.stats);
//		        console.log(result.map)

				var css = result.css.toString();

				descriptor.descriptor.code = css;
				descriptor.descriptor.format = "utf8";

				return callback(null);
		});

	} else
	if (descriptor.descriptor.format === "css") {

		var source = descriptor.descriptor.code;

		// TODO: Use dependencies info from descriptor to inline static imports and assets once declared and scanned by pinf-it-module-insight
		source = REWORK(source)
		    .use(REWORK_IMPORT({
		    	path: options._realpath(options.packageExtras.packagePath)
		   	}))
		    .toString();

		source = source.replace(/(background[\s\w-]*:[\s#\w]*]*)url(\('?"?images\/)/g, "$1inline$2");

		source = REWORK(source)
				.use(REWORK_INLINE(options._realpath(options.packageExtras.packagePath)))
				.use(REWORK_COMMENTS)
		    .toString();

		descriptor.descriptor.code = source;

		descriptor.descriptor.format = "utf8";
	}

	return callback(null);
}
Пример #6
0
  return through.obj(function(file, enc, cb) {
    var processedCss;

    if (file.isStream()) {
      this.emit('error', new gutil.PluginError('gulp-concat-css', 'Streaming not supported'));
      return cb();
    }

    if(!firstFile) {
      firstFile = file;
      commonBase = file.base;
    }

    function urlPlugin(file) {
      return reworkUrl(function(url) {
        if(isUrl(url) || isDataURI(url) || path.extname(url) === '.css' || path.resolve(url) === url) {
          return url;
        }

        var resourceAbsUrl = path.relative(commonBase, path.resolve(path.dirname(file), url));
        resourceAbsUrl = path.relative(destDir, resourceAbsUrl);
        //not all systems use forward slash as path separator
        //this is required by urls.
        if(path.sep === '\\'){
          //replace with forward slash
          resourceAbsUrl = resourceAbsUrl.replace(/\\/g, '/');
        }
        return resourceAbsUrl;
      });
    }


    function collectImportUrls(styles) {
      var outRules = [];
      styles.rules.forEach(function(rule) {
        if(rule.type !== 'import') {
          return outRules.push(rule);
        }

        var importData = parseImport('@import ' + rule.import + ';');
        var importPath = importData && importData[0].path;
        if(isUrl(importPath) || !options.inlineImports) {
          return urlImportRules.push(rule);
        }
        return outRules.push(rule);
      });
      styles.rules = outRules;
    }


    function processNestedImport(contents) {
      var rew = rework(contents);
      if(options.rebaseUrls) {
        rew = rew.use(urlPlugin(this.source));
      }
      rew = rew.use(collectImportUrls);
      return rew.toString();
    }

    try {
      processedCss = rework(String(file.contents||""));
      if(options.rebaseUrls) {
        processedCss = processedCss.use(urlPlugin(file.path));
      }

      processedCss = processedCss.use(collectImportUrls);

      if(options.inlineImports) {
        processedCss = processedCss.use(reworkImport({
          path: [
            '.',
            path.dirname(file.path)
          ].concat(options.includePaths),
          transform: processNestedImport
        }))
          .toString();
      }

      processedCss = processedCss.toString();
    } catch(err) {
      this.emit('error', new gutil.PluginError('gulp-concat-css', err));
      return cb();
    }

    buffer.push(processedCss);
    cb();
  }, function(cb) {
  return through.obj(function(file, enc, cb) {
    if (file.isStream()) {
      this.emit('error', new gutil.PluginError('gulp-concat-css', 'Streaming not supported'));
      return cb();
    }

    if(!firstFile) {
      firstFile = file;
      commonBase = file.base;
    }

    function urlPlugin(file) {
      return reworkPluginFunction({url: function() {
        var rawUrl = Array.prototype.slice.apply(arguments).join(',');
        var url = rawUrl.split('"').join('');
        url = url.split('\'').join('');
        url = url.trim();

        if(isUrl(url) || isDataURI(url) || path.extname(url) === '.css' || path.resolve(url) === url) {
          return 'url(' + rawUrl + ')';
        }
        var resourceAbsUrl = path.relative(commonBase, path.resolve(path.dirname(file), url));
        resourceAbsUrl = path.relative(destDir, resourceAbsUrl);
        //not all systems use forward slash as path separator
        //this is required by urls.
        if(path.sep === '\\'){
          //replace with forward slash
          resourceAbsUrl = resourceAbsUrl.replace(/\\/g, '/');
        }
        return 'url("' + resourceAbsUrl + '")';
      }});
    }


    function collectImportUrls(styles) {
      var outRules = [];
      styles.rules.forEach(function(rule) {
        if(rule.type !== 'import') {
          return outRules.push(rule);
        }

        var importData = parseImport('@import ' + rule.import + ';');
        if(isUrl(importData.path)) {
          return urlImportRules.push(rule);
        }
        return outRules.push(rule);
      });
      styles.rules = outRules;
    }


    function urlRewrite(contents, file) {
      return rework(contents)
        .use(urlPlugin(file))
        .use(collectImportUrls)
        .toString()
    }

    try {
      var processedCss = rework(String(file.contents))
        .use(urlPlugin(file.path))
        .use(collectImportUrls)
        .use(reworkImport({
          path: [
            '.',
            path.dirname(file.path)
          ],
          transform: urlRewrite
        }))
        .toString();
    } catch(err) {
      this.emit('error', new gutil.PluginError('gulp-concat-css', err));
      return cb();
    }

    buffer.push(processedCss);
    cb();
  }, function(cb) {