HTML Injector

BrowserSync html 注入器。「BrowserSync html injector」

  • 所有者: shakyShane/html-injector
  • 平台:
  • 許可證:
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

HTML Injector Build Status

Browsersync plugin for injecting HTML changes without reloading the browser. Requires an existing page with a <body> tag.

Install (Node V4.0.0 & above)

$ npm i browser-sync bs-html-injector

Install (Node V0.10.x 0.12.x)

$ npm i browser-sync bs-html-injector@2

Examples & Recipes including html-injection

Options

files - String, Array
File watching patterns that will trigger the injection. NOTE: Ensure you are
not also watching the same file through the regular Browsersync
config - this will cause a full reload and the inject will not happen

browserSync.use(require("bs-html-injector"), {
    files: ["app/*.html", "app/templates/**"]
});

restrictions - Array
Limit the comparisons to a certain elements.

browserSync.use(require("bs-html-injector"), {
    files: "app/*.html",
    restrictions: ['#header', '#footer']
});

excludedTags - Array
When working from scratch within the body tag, the plugin will work just fine. But when you start
working with nested elements, you might want to add the following configuration to improve the
injecting.

browserSync.use(require("bs-html-injector"), {
    files: "app/*.html",
    excludedTags: ["BODY"]
});

Example

Create a file called bs.js and enter the following: (update the paths to match yours)

// requires version 2.0 of Browsersync or higher.
var browserSync  = require("browser-sync").create();
var htmlInjector = require("bs-html-injector");

// register the plugin
browserSync.use(htmlInjector, {
    // Files to watch that will trigger the injection
    files: "app/*.html" 
});

// now run Browsersync, watching CSS files as normal
browserSync.init({
  files: "app/styles/*.css"
});

Gulp example

var gulp         = require("gulp");
var browserSync  = require("browser-sync").create();
var htmlInjector = require("bs-html-injector");

/**
 * Start Browsersync
 */
gulp.task("browser-sync", function () {
    browserSync.use(htmlInjector, {
        files: "app/*.html"
    });
    browserSync.init({
        server: "test/fixtures"
    });
});

/**
 * Default task
 */
gulp.task("default", ["browser-sync"], function () {
    gulp.watch("test/fixtures/*.html", htmlInjector);
});

Grunt example

// This shows a full config file!
module.exports = function (grunt) {
    grunt.initConfig({
        watch: {
            files: 'app/scss/**/*.scss',
            tasks: ['bsReload:css']
        },
        sass: {
            dev: {
                files: {
                    'app/css/main.css': 'app/scss/main.scss'
                }
            }
        },
        browserSync: {
            dev: {
                options: {
                    watchTask: true,
                    server: './app',
                    plugins: [
                        {
                            module: "bs-html-injector",
                            options: {
                                files: "./app/*.html"
                            }
                        }
                    ]
                }
            }
        },
        bsReload: {
            css: "main.css"
        }
    });

    // load npm tasks
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-browser-sync');

    // define default task
    grunt.registerTask('default', ['browserSync', 'watch']);
};

主要指標

概覽
名稱與所有者shakyShane/html-injector
主編程語言JavaScript
編程語言JavaScript (語言數: 2)
平台
許可證
所有者活动
創建於2014-08-08 23:11:34
推送於2018-01-13 14:57:15
最后一次提交2017-11-02 09:00:18
發布數20
最新版本名稱v3.0.3 (發布於 2016-09-06 21:33:57)
第一版名稱1.0.0 (發布於 )
用户参与
星數77
關注者數7
派生數21
提交數81
已啟用問題?
問題數23
打開的問題數9
拉請求數4
打開的拉請求數2
關閉的拉請求數3
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?