Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including gulp-html-import2 with all npm packages installed. Try it out:

var gulpHtmlImport2 = require("gulp-html-import2")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

gulp-html-import2 v0.0.4

A gulp plugin which can import .html files into .html files

gulp-html-import2

This is forked npm (gulp-html-import).

A gulp plugin which can import .html files into .html files

Usage

First, install gulp-html-import2 as a devDependency:

npm install gulp-html-import2 --save-dev

Then add it to the gulpfile.js:

var htmlImport = require('gulp-html-import2');

gulp.task('import', function () {
    gulp.src('./demo/index.html')
        .pipe(htmlImport('./demo/components/'))
        .pipe(gulp.dest('dist')); 
})

Example

Here is the files tree:

|
-- demo
|   |
|   -- components
|   |    |
|   |    -- header.html
|   |    |
|   |    -- footer.html
|   |
|   -- index.html
|
-- gulpfile.js

Html files:

<!-- index.html -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Gulp-html-import Example</title>
</head>
<body>
    <!-- @import "header.html" -->
    <p>Hello World</p>
    <!-- @import "footer.html" -->
</body>
</html>

In your index.html, you should use

<!-- @import "XXX.html" -->

to import your components.

<!-- header.html -->

<h1>I am the header</h1>
<!-- footer.html -->

<h1>I am the footer</h1>

When you get into the root directory(where your gulpfile.js is) and type

gulp import

you could see a html file in /dist like this:

<!-- /dist/index.html -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Gulp-html-import Example</title>
</head>
<body>
    <h1>I am the header</h1>
    <p>Hello World</p>
    <h1>I am the footer</h1>
</body>
</html>

Everything is OK.

API

htmlImport(string)

string

Type: String

The url of your components


MIT

Copyright © 2016 Jrain Lau

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free