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

autoloader-cdn

v1.0.2

Published

CDN autoloader based on package.json dependencies and unpkg.com(cdn service)

Downloads

3

Readme

Autoloader CDN based on package.json dependencies, and unpkg.com

Useful when you needed to load everything from one file, for example a library with tons of dependencies, you won't bundle everything, just create 5kb autoloader.js file in your project.

Install

You can install this package with npm.

npm

npm install --save autoloader-cdn

CDN

Can also be found on unpkg.com:

//unpkg.com/[email protected]/dist/autoloader.cdn.js
//unpkg.com/[email protected]/dist/autoloader.cdn.min.js

Basic usage example

1. Add a <script> tag to your index.html
    <script src="../dist/autoloader.cdn.js"></script>
    <script type="text/javascript">
         var autoloader = autoloaderCdn({
             env: 'development',
             deps: true,
             pkgDependencies: {
                 "jquery": "^1.8.2"
             },
             loadDependencies: {
                 "jquery": {
                     version: "3.3.1"
                 },
                 "video.js": {
                     fileName: 'video',
                     version: "7.0.5"
                 }
             }
         });
        autoloader.loadjs.ready('bundle', function() {
            $('body').html('Jquery works!!');
        });
    </script>

Available options here

  • env environment variable(development,production), if production, will load minified files (default production)
  • pkgDependencies usually that's the place to put package.json dependencies directly (default: {}), it has two parameters: package name, and it's version.
  • loadDependencies the order of dependencies are loaded, and each with following parameters by default:
{
    pkgName: key,
    version: pkgDependencyVersion,
    path: '/dist/',
    fileName: key,
    fileMin: '.min',
    fileExt: '.js'
}
  • urlTemplate The url structure (default: https://unpkg.com/[pkgName]@[version][path][fileName][fileMin][fileExt]), unrecommended to change.

Recommended usage example(webpack)

A recommended way is to use js precompilers, that allows to include the package.json, and send all the dependencies to the configuration automatically, so in this case the dependencies versions will be parsed from package.json. include it to pkgDependencies parameter.

1. Create new file autoloader.js, add it for webpack - entry.autoloader, then use this:
// provide the path to package.json, or use webpack DefinePlugin insead.
var pkg = require('./package'); 
// require the library
var autoloaderCdn = require('autoloader-cdn');
// library initialization
var autoloader = autoloaderCdn({
             env: 'development',
             pkgDependencies: pkg.dependencies,
             loadDependencies: {
                 "jquery": {
                     version: "3.3.1"
                 },
                 "video.js": {
                     fileName: 'video',
                     version: "7.0.5"
                 }
             }
         });
// export
module.exports = autoloader.loadjs;

Create UMD library from this file, for example with webpack name the library autoloader, also it's recommended to use webpack.DefinePlugin, to set only dependencies from package.json.

2. After all, it would look like this:

<script src="autoloader.js"
            deps="true"
            deps-before="anotherCss.css"
            deps-after="cssExample.css,scriptExample.js">
</script>
<script>
autoloader.ready('bundle', function() {
        $('body').html('Jquery works!!');
    });
</script>

Available options here:

  • deps dependencies should be included? (default false)
  • deps-exclude what to exclude from dependencies (sepparated by comma ,, ex: jquery,bootstrap)
  • deps-before what to include before all dependencies added (sepparated by comma ,, ex: https://code.jquery.com/jquery-2.2.4.min.js,https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js)
  • deps-after the same like deps-before but the opposite .

For now that's all, in the future this will be improved in a common manner.

Change Log

9th July 2018

  • [geoshar] First 1.0.0 version added.
  • [geoshar] First documentation added.

Copyright © 2018 Georgy Sharapov | BSD & MIT license