npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-inject-in-html

v1.2.0

Published

Inject or include HTML/CSS/Javascript files into HTML with gulp.

Downloads

339

Readme

gulp-inject-in-html

Inject or include HTML/CSS/Javascript files into HTML with gulp.

Install

npm install gulp-inject-in-html --save-dev

How to use?

const gulp = require('gulp');
const injectHTML = require('gulp-inject-in-html');

// After PUG, SASS, SCSS, Typescript, Javascript,... are translated or compiled
gulp.task('inject-in-html', function() {
  gulp.src('dist/**/*.html')
    .pipe(injectHTML())
    .pipe(gulp.dest('dist/'));
});

In the .pug or .html files, specify the relative path to injected/included targets.

html
  head ...
    <!-- inject(css) [css/main.min.css] -->
  body
    <!-- inject(html) [header.html] -->
    <!-- inject(js) [js/main.min.js] -->

or

<html>
  <head>
    ...
    <!-- inject(css) [css/main.min.css] -->
  </head>
  <body>
    <!-- inject(html) [header.html] -->
    <!-- inject(js) [js/main.min.js] -->
  </body>
</html>

And it will translated to the behind code.

<html>
  <head>
    ...
    <link href="css/main.min.css" rel="stylesheet" />
  </head>
  <body>
    <header>
      ...some html contents of header.html
    </header>
    <script src="js/main.min.js" type="text/javascript"></script>
  </body>
</html>

Options

Common usage (including mode)

input

<!-- inject(css) [css/main.min.css] -->

output

<link href="css/main.min.css" rel="stylesheet" />

Multiple Files

input

<!-- inject(css) [css/main.min.css, css/header.min.css, css/footer.min.css] -->

output

<link href="css/main.min.css" rel="stylesheet" />
<link href="css/header.min.css" rel="stylesheet" />
<link href="css/footer.min.css" rel="stylesheet" />

Injection mode

input

<!-- inject(css)(inject) [css/main.min.css] -->

output

<style>
body { ... }
...
</style>

Note: HTML file can only supported injection mode.

Async/Defer (only for javascript)

input

<!-- inject(js)(async) [js/main.min.js] -->
<!-- inject(js)(inject)(defer) [js/index.min.js] -->
<!-- inject(js)(async)(defer) [js/handler.min.js] -->

output

<script src="js/main.min.js" type="text/javascript" async></script>
<script type="text/javascript" defer>
  // ...some javascript codes of js/index.min.js
</script>
<script src="js/handler.min.js" type="text/javascript" async defer></script>

Write annotation

input

<!-- inject(html) [header.html] {Here is header block} -->

output

<!-- Here is header block -->
<header>
  ...some html contents of header.html
</header>