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-resolve-import

v1.0.18

Published

Used to import js files using grammar: '<link rel = "import" href = "filepath">'. It supports mult-level imports and automatically adjust the resource reference path to be relative to the containing html file. The '<img>', '<audio>', '<video>', '<script>'

Downloads

12

Readme

gulp-resolve-import Build Status Coverage Status

[NPM]

Used to import file content using grammar: '<link rel = "import" href = "filepath">'. It supports multi-level imports and automatically adjust the resource reference path to be relative to the containing html file. The <img>, <audio>, <video>, <script>, <source> and <src-placeholder> tags, and inline style background url are supported.

Usage

  1. Declare imports in your file

/a.html

  <link rel = "import" href = "sub/b.jsref.html">

/sub/b.jsref.html

  <audio src = "asset/aud.mp3"></audio>
  <span style = "background-image: url(../1.png)"></span>

  <script type = "text/javascript" src="../../js/a.js"></script>
  <script type = "text/javascript">alert("Hello");</script>
  <script type = "text/javascript" src="../../js/b.js"></script>

  <link rel = "import" href = "sub2/c.jsref.html">

/sub/sub2/c.jsref.html

  <script type = "text/javascript" src="c.js"></script>
  <script type = "text/javascript">alert("World");</script>
  1. Specify the action in the build script.
  var gulp = require("gulp"),
      resolveImport = require("gulp-resolve-import");
    
  gulp.src("*.html").pipe(resolveImport());

The resulting html for a.html will be like:

  <audio src = "sub/asset/aud.mp3"></audio>
  <span style = "background-image: url(1.png)"></span>

  <script type = "text/javascript" src="../js/a.js"></script>
  <script type = "text/javascript">alert("Hello");</script>
  <script type = "text/javascript" src="../js/b.js"></script>

  <script type = "text/javascript" src="sub/sub2/c.js"></script>
  <script type = "text/javascript">alert("World");</script>

Supported source declaration

For html, this plugin currently handle the following html tags and corresponding attribute names to dynamically adjust the asset references:

  1. link - href
  2. script - src
  3. img - src
  4. audio - src
  5. video - src
  6. source - src
  7. src-placeholder - src

You can use src-placeholder tag to let this plugin help manage the source that you may need to dynamically assign asset source, like:

    <audio></audio>
    <src-placeholder data-type = "ogg" src = "asset/m.ogg"></src-placeholder>
    <src-placeholder data-type = "m4a" src = "asset/m.m4a"></src-placeholder>
    <src-placeholder data-type = "mp3" src = "asset/m.mp3"></src-placeholder>
    var audioObj = document.querySelector("audio");
    var extNameAndTypes = {
        "ogg": "audio/ogg",
        "m4a": "audio/mpeg",
        "mp3": "audio/mpeg"
    };
    
    ["ogg", "m4a", "mp3"].forEach(function(extName){
        var sourceObj = document.createElement("source");
        sourceObj.type = extNameAndTypes[extName];
        sourceObj.src = document.querySelector("[data-type=" + extName + "]").getAttribute("src");
        audioObj.appendChild(sourceObj);
    });

For css, keyword url is used to identify potential asset reference.

Options

baseAbsolutePath {String}

Used as the base path to determine the final relative path of referring resources. Default to be the folder of the processing file.

prependText {String}

The text to be prepended while resolving imports. Default to be an empty string.

linkMetaFilter {Function}

The filter method is used to select imports to resolve, i.e., resolve imports conditionally. The method takes 1 argument of type: {LinkMeta} which has the following methods:

  1. {Boolean} hasAttribute({String} name). Test if the <link> tag has the specified attribute.
  2. {String} getAttribute({String} name). Get the specified attribute value.
linkMetaFilter_applyRecursively {Boolean}

Specify whether or not apply the filter method in the resolved import content. Default to be true.

License

MIT