Git Product home page Git Product logo

gulp-map-transform's Introduction

gulp-map-transform

Version CircleCI License

Easily transform virtual paths inside any file to real paths

Install

Install via npm:

npm install --save-dev gulp-map-transform

Usage

Transforming scss paths to compiled css paths

Given this section of a html file:

...
<head>
  <link rel="stylesheet" href="@styles/test.scss" />
</head>
...

And this configuration inside your gulpfile

const { src, dest } = require('gulp');
const sass = require('gulp-sass');
const mapTransform = require('gulp-map-transform');

const OUT_PATH = '/dist/folder';

src('/html/files/**/*.html')
  .pipe(
    mapTransform({
      search: /href="@styles\/(.*?).scss"/gi,
      replace: /"(.*?)"/i,
      rootPath: OUT_PATH,
      rewrite: (path) => path.replace('@styles', 'css/files'),
      transform: (stream) => stream
        .pipe(sass())
        .pipe(dest(path.join(OUT_PATH, 'css')))
    })
  )
  .pipe(dest(OUT_PATH))

This will generate the following html file after compiling the css file:

...
<head>
  <link rel="stylesheet" href="/css/files/test.css" />
</head>
...

Options

Name Type Required Description
search RegExp yes This expression is used to identify in which location you want to execute a transformation of the content
replace RegExp yes This is used to replace the path of the file inside a result of the search matches
rewrite  Function  yes Use this to tell what and how to replace the path inside the string found by the replace expression
 transform  Function yes In this callback you get a separate stream to handle all your files already present with the real path
 rootPath  string  no The root path to which the transfomed file paths will be appended (with path.relative())

License

See the LICENSE file for license rights and limitations (MIT).

gulp-map-transform's People

Contributors

davideperozzi avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.