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

av-gulp-injector

v1.0.4

Published

A nodeJs / gulp module in complement of gulp-asset to automatically import assets to your files

Downloads

6

Readme

av-gulp-injector

A nodeJs / gulp module in complement of gulp-asset to automatically import assets to your files

Pre-requesite

This node.js modules provide a function design to be implemented into a gulp.js task, please refer on the doc to learn more about gulp.

Download

You can download the node package via npm

npm install --save-dev av-gulp-injector

Usage

Av-gulp-injector embeds gulp inject , limit its usage to the AppVentus Workflow's needs (oriented Symfony) and add features like json imports and path aliases.

Basics

Av-gulp-injector will look for JSON files named injector.json all over your architecture. The content of thoses files must be on this model :

{
    "tag": [
        "path/to/an/asset.js",
        "path/to/an/asset.css",
    ],
    ...
}

Running the gulp task below will make av-gulp-injector looking for all the injector.json files and import the dependencies listed into the gulp.src object parameter of the avInjector.injector() method.

var gulp = require('gulp');
var avInjector = require('av-gulp-injector');

gulp.task('injector', function() {
    avInjector.injector(gulp.src('index.html'));
});

The importation works with tag, that means that the template which will receive the assets to inject has to have comments to show where to import assets. (Please refer to the gulp inject doc for more details).

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>Acme</title>

        <!-- tag:css -->
        <!-- endinject -->

        <!-- tag:js -->
        <!-- endinject -->
    </head>

    <body></body>
</html>

Aliases

Into your injector.json you can use aliases that will avoid you to specify a part of the path. During the importation the alias will be replace by the real path partial.

It can be usefull if you develop a component that can be available with bower or npm and you don't know where the location of the bower_components or node_modules folders.

For example I have a injector.json file like this one :

{
    "head": [
        "@bower/my-component/style.css",
    ],
}

If you want to inject the style.css referenced with a @bower alias, you have to create an javascript object that will be passed as second argument of the method avInjector.injector() as shown below;

var gulp = require('gulp');
var avInjector = require('av-gulp-injector');

var injectorAliases = {
    '@bower': 'bower_components',
}

gulp.task('injector', function() {
    avInjector.injector(gulp.src('index.html'), injectorAliases);
});

The task injector will import the file at the path bower_components/my-component/style.css

File import

As this workflow is made for Symfony2 the import of css and html files will be with a path wrapped by the function asset(), and paths that starts with web/ will be cut off the web folder reference.

Av-gulp-injector supports injection into .html.twig & scss files.

You can pass a third argument into the avInjector.injector() method that is a boolean for setting the path injections in relative way. By default, this argument is false.