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-web-dependencies

v1.2.0

Published

Parse your HTML/JS file and copy bower/npm files to your destination directory

Downloads

26

Readme

Gulp Web Dependencies

Parse your HTML/JS file and copy bower/npm dependencies to your destination directory

npm Build status Test coverage Buy me a beer

Install

npm install --save-dev gulp-web-dependencies

Usage

The project structure:

project/
├── bower_components
│   ├── bootstrap
│   │   └── dist
│   │       ├── css
│   │       │   ├── bootstrap.min.css
│   │       │   ├── bootstrap-theme.min.css
│   │       │   └── ...
│   │       └── js
│   │           ├── bootstrap.min.js
│   │           └── ...
│   ├── require1k
│   │   └── require1k.min.js
│   └── jquery
│       └── dist
│           ├── jquery.min.js
│           └── ...
├── node_modules
│   ├── angular
│   │   └── angular.min.js
│   └── firebase
│       ├── app.js
│       ├── auth.js
│       └── ...
├── src
│   ├── index.html
│   └── app.js
└── gulpfile.js

Use relative paths for NPM/Bower dependencies:

The index.html:

<!doctype html>
<html>
    <head>
        <title>Test file</title>
        <meta charset="utf-8">
        <link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.min.css">
        <link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap-theme.min.css">
    </head>
    <body>
        <h1>Page title</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur tempus enim leo, ac lacinia purus accumsan sit amet. In ultrices sagittis nulla, ut dapibus.</p>
        
        <script src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
        <script src="../bower_components/jquery/dist/jquery.min.js"></script>
        <script src="../node_modules/angular/angular.min.js"></script>
        <script src="../bower_components/require1k/require1k.min.js" data-main="./app"></script>
    </body>
</html>

The app.js:

var _app = require('../node_modules/firebase/app');
var _auth = require('../node_modules/firebase/auth');

// ...

In your gulpfile.js, add the task:

var gulp = require('gulp')
  , dependencies = require('gulp-web-dependencies');

var path_dest = 'dist';

gulp.task('dependencies', function() {
    return gulp.src('src/index.html')
        .pipe(dependencies({
            dest: path_dest,    // The basedir of your application. default: path.dirname(file.path)
            prefix: '/vendor',  // The URL prefix. Default "/"
        }))
        .pipe(gulp.dest(path_dest));
});

// or using a template preprocessing (pug)
gulp.task('dependencies-jade', function() {
    return gulp.src('src/app.js')
        .pipe(pug())
        .pipe(dependencies({
            dest: path_dest, 
            prefix: '/vendor',
        }))
        .pipe(gulp.dest(path_dest));
});

// parsing js files
gulp.task('dependencies-js', function() {
    return gulp.src('src/app.js', { base: 'src' })
        .pipe(dependencies({
            dest: path_dest,
            base: 'src' // the gulp.src base value
        }))
        .pipe(gulp.dest(path_dest));
});

// Gulp Default Task
gulp.task('default', ['dependencies', 'dependencies-jade', 'dependencies-js']);

After the build, get:

project/
├── bower_components
│   └── ...
├── dist
│   ├── index.html
│   ├── products.html
│   ├── node_modules
│   │   └── firebase
│   │       ├── app.js
│   │       └── auth.js
│   └── vendor
│       ├── angular
│       │   └── angular.min.js
│       ├── bootstrap
│       │   └── dist
│       │       ├── css
│       │       │   ├── bootstrap.min.css
│       │       │   └── bootstrap-theme.min.css
│       │       └── js
│       │           └── bootstrap.min.js
│       └── jquery
│           └── dist
│               └── jquery.min.js
├── node_modules
│   └── ...
├── src
│   ├── index.html
│   └── app.js
└── gulpfile.js

index.html:

<!doctype html>
<html>
    <head>
        <title>Test file</title>
        <meta charset="utf-8">
        <link rel="stylesheet" href="/vendor/bootstrap/dist/css/bootstrap.min.css">
        <link rel="stylesheet" href="/vendor/bootstrap/dist/css/bootstrap-theme.min.css">
    </head>
    <body>
        <h1>Page title</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
        
        <script src="/vendor/bootstrap/dist/js/bootstrap.min.js"></script>
        <script src="/vendor/jquery/dist/jquery.min.js"></script>
        <script src="/vendor/angular/angular.min.js"></script>
        <script src="plugins.js"></script>
    </body>
</html>

app.js:

var _app = require('firebase/app');
var _auth = require('firebase/auth');

// ...

Use the your own search folders pattern

You can use the the folders option to define your search folders pattern. Each folder is separated by a pipe |:

gulp.task('dependencies', function() {
    return gulp.src('src/**/*.pug')
        .pipe(pug())
        .pipe(dependencies({
            folders: 'bower|assets',
            dest: 'dist',
            prefix: '/vendor',
        }))
        .pipe(gulp.dest('dist'));
});

Use the flat option

gulp.task('dependencies', function() {
    return gulp.src('src/**/*.pug')
        .pipe(pug())
        .pipe(dependencies({
            dest: 'dist',
            prefix: '/vendor',
            flat: true
        }))
        .pipe(gulp.dest('dist'));
});

After the build, get:

project/
├── ...
├── dist
│   ├── ..
│   └── vendor
│       ├── angular.min.js
│       ├── bootstrap.min.css
│       ├── bootstrap.min.js
│       ├── bootstrap-theme.min.css
│       └── jquery.min.js
├── ...
<!doctype html>
<html>
    <head>
        <title>Test file</title>
        <meta charset="utf-8">
        <link rel="stylesheet" href="/vendor/bootstrap.min.css">
        <link rel="stylesheet" href="/vendor/bootstrap-theme.min.css">
    </head>
    <body>
        <h1>Page title</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
        
        <script src="/vendor/bootstrap.min.js"></script>
        <script src="/vendor/jquery.min.js"></script>
        <script src="/vendor/angular/angular.min.js"></script>
        <script src="plugins.js"></script>
    </body>
</html>

License

Under the MIT license. See LICENSE file for more details.