Socket
Socket
Sign inDemoInstall

gulp-replace-relative

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-replace-relative

A string replace plugin for gulp based on the processed file


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

js-standard-style

gulp-replace-relative

Replace matched content in files with support for relative paths

Similar to gulp-replace this plugin allows to change the files content and like gulp-replace-async it supports asynchronous tasks to retrieve data. It can be used for relative includes and source transformation on demand.

Install

$ npm install --save-dev gulp-replace-relative

Usage

var replaceRelative = require('gulp-replace-relative')

gulp.task('replace', function(){
	return gulp.src('index.js')
						 .pipe(replaceRelative(/pattern-(.*?)/g, function (file, match, callback) {
							 console.log(file, match)
						 })
})

Process file transformation ("like webpack loaders on the server")

gulp.task('replace', function(){
	return gulp.src('index.js')
				 .pipe(replaceRelative(/require\('\.\/(.*?\.styl')\/g, function (file, match, callback) {
					 var includePath = match.match(/\('(.*?\.styl)'\)/)[1]						 
					 fs.readFile(path.resolve(path.dirname(file.path), includePath), function (error, data) {
						 var css = stylus(data.toString()).render()
						 postcss([
						  autoprefixer({
							 browsers: ['last 2 versions']
							}),
							cssnano
						 ])
						 .process(css)
						 .then(function (result) {
						  return callback('"' + result.css + '"')
						 })
					 })
				 })
})

API

replaceRelative(pattern, replacer)

Returns a transform stream.

pattern

Type: string, regex

Defines the pattern to match.

replacer

Type: string, function

A defined function retrieves following parameters: replace(file, match, callback)

TODO

  • add tests

Keywords

FAQs

Package last updated on 05 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc