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

grunt-inject-js

v0.1.10

Published

Grunt Task that allows for multiple JavaScript files to injected into a file.

Downloads

95

Readme

grunt-inject-js v.0.1.10

npm version

Grunt task that allows for multiple js files to be injected into a file. Inspired by grunt-inject

Getting Started

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-inject-js --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-inject-js');

The injectjs task

Overview

Run this task with the grunt injectjs command.

Task targets, files and options may be specified according to the Grunt Configuring tasks guide.

The task is to allow for the injection of multiple javascript scripts into a document at defined places in the document. The use case arose when having to inject different third party analytics code at different locations.

grunt.initConfig({
   injectjs: {
       dev:
        {
          files:{
            'test/output/index.html': 'test/fixtures/index.html'
          },
          scriptsrc: 'test/fixtures/*.js'
        }
      }
});

Required properties

files

Type: Grunt file configuration

The src HTML files must have the following comment(s) which are replaced by the injected JavaScript:

<!-- inject:[jsfile] -->

where [jsfile] is the JavaScript file name to be injected. The file extension .js should be omitted.

The follow configuration would inject three files into the html document at the specified locations:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Grunt Inject JS Test file</title>
    <!-- inject:google -->
    <!-- inject:woopra -->
</head>
<body>
<h1>Test File</h1>
<p>
    Content of test file
</p>
<!-- inject:pardot -->
</body>
</html>

Optional properties

scriptsrc

Type: String || Array || file glob

The path of the script(s) to be injected into the page.

It is recommended to have a directory that includes all the JavaScript files to be injected. A warning is raised if the directory contains non-JavaScript files.

This property is ignored if clear is set to true.

clear

Type: Boolean

If this property is set to true then the scriptsrc is ignored and all tags following the pattern

<!-- inject:[A-Za-z]* --> are removed from the file.

This property was added as in some environments no Javascript files need to be injected and all inject placeholders removed from the file(s).

Release History

* 2016-07-14   v0.1.10  
* 2016-07-14   v0.1.9  
* 2015-01-16   v0.1.8   Beta Version
* 2015-01-16   v0.1.7   Beta Version
* 2015-01-14   v0.1.6   Beta Version
* 2015-01-13   v0.1.5   Beta Version
* 2015-01-13   v0.1.4   Beta Version
* 2015-01-13   v0.1.3   Beta Version
* 2015-01-13   v0.1.2   Beta Version
* 2015-01-12   v0.1.1   Beta Version
* 2015-01-12   v0.1.0   Beta Version