Giter Site home page Giter Site logo

Comments (3)

bmacnaughton avatar bmacnaughton commented on June 20, 2024

If it turns out that there isn't a way to do this using this package you might want to give gulp-markers a try. gulp-html-replace was my inspiration but gulp-markers is basically a thin wrapper around JavaScript's regex.

The simplest way to do what your looking at is to define some kind of marker in the file, like

<!-- @css -->app.css where app.css is replaced by whatever filename you want.

But what it looks like is your decision - it just needs to be uniquely identifiable by a regular expression.

Then define the marker object and add it to the markers instance.

var markers = new require('gulp-markers')
markers.addMarker({
  tag: 'css-replacement',           // this is for your context only
  re: /<!-- @css -->(\S+) /,        // this just finds your marker defined above
  // the arguments of the function are context (tag, et al), the match, and the groups
  replace: function (context, match, filename) {
    return filename                    // this is what replaces the matched expression
  }
})

You can get more sophisticated by putting all the expressions in a block but that requires writing a pretty ugly regex or doing replace-function regex processing on each line within the block.

Apologies to Vladimir if this is inappropriate; I'm happy to delete this comment. I don't recall whether what is being asked is easy to do or not but I ended up writing gulp-markers based on your idea because I kept finding odd corner cases I wanted to address.

from gulp-html-replace.

claudchan avatar claudchan commented on June 20, 2024

Thanks but kind of complicated.
Is there any cleaner way or is there a gulp plugin can do such thing easily?

from gulp-html-replace.

claudchan avatar claudchan commented on June 20, 2024

I think i found a good solutions, using gulp-replace.
Now i can find all src '*.html' and find replace 'app.css' with 'app.min.css'.

from gulp-html-replace.

Related Issues (20)

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.