Git Product home page Git Product logo

gulp-html-replace's Introduction

gulp-html-replace

Replace build blocks in HTML with links to combined/compressed scripts or styles.

Usage

Install gulp-html-replace as a development dependency:

npm install --save-dev gulp-html-replace

Blocks in your HTML file should look like this:

<!-- build:<name> -->
...
<!-- endbuild -->

name is the replacement task name.

Syntax looks like this:

// single task name replacement
htmlreplace('js', 'scripts/bundle.min.js')

// single task with multiple files
htmlreplace('css', ['normalize.css', 'main.css'])

// multiple tasks
htmlreplace({
    'javascripts': 'bundle.js',
    'styles': ['style.css', 'new.css']
})

Correct tags will be determined automatically based on file extensions. Currently supported js and css.

Blocks with orphaned task names will be removed.

Example

index.html:

<!DOCTYPE html>
<html>
    <head>
    .....
    <!-- build:styles -->
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/main.css">
    <!-- endbuild -->
    .....
    </head>
    <body>
    .....
    <!-- build:js -->
    <script src="js/player.js"></script>
    <script src="js/monster.js"></script>
    <script src="js/world.js"></script>
    <!-- endbuild -->
    .....

gulpfile.js:

var htmlreplace = require('gulp-html-replace');

gulp.task('default', function() {
  gulp.src('index.html')
    .pipe(htmlreplace({
        'styles': 'styles.min.css',
        'js': 'js/bundle.min.js'
    }))
    .pipe(gulp.dest('build/'));
});

Result:

<!DOCTYPE html>
<html>
    <head>
    .....
    <link rel="stylesheet" href="styles.min.css">
    .....
    </head>
    <body>
    .....
    <script src="js/bundle.min.js"></script>
    .....

gulp-html-replace's People

Contributors

vfk avatar

Watchers

 avatar  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.