0.0.2 • Published 8 years ago

gulp-html-import v0.0.2

Weekly downloads
318
License
MIT
Repository
-
Last release
8 years ago

gulp-html-import

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

Usage

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

npm install gulp-html-import --save-dev

Then add it to the gulpfile.js:

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

gulp.task('import', function () {
    gulp.src('./demo/index.html')
        .pipe(gulpImport('./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