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

external-url-loader

v0.1.0-alpha.5

Published

A loader for webpack that permit static's usage as externals

Downloads

87

Readme

npm node deps tests size

External-url-loader

A loader for webpack that permit static's usage as externals that make reference to your own package. If those statics not exceed the limit size you specify, it will be encoded in base64.

The loader will generate a path with a require that make reference to the packageName you specify.

This is useful when you want to create a library that use statics dependencies.


Getting Started

To begin, you'll need to install external-url-loader:

$ npm install external-url-loader --save-dev

This loader provides the same feature as url-loader and extends all url-loader options.

import img from './image.png';
// webpack.config.js
module.exports = {
    module: {
        rules: [
            {
                test: /\.(png||jpe?g|gif|svg)$/i,
                use: [
                    {
                        loader: 'external-url-loader',
                        options: {
                            limit: 8192, // url-loader limit
                            packageName: 'library-package-name', // your package name
                            active: process.env.NODE_ENV === 'production', // if you want to enable or disable external-url-loader and fallback on url-loader
                        },
                    },
                ],
            },
        ],
    },
};

More over you have to add your own library, and all sub paths as externals in your build process.

:warning: Don't put externals in your dev-server process. (you can make another config dedicated to dev-server)

// webpack.config.js
module.exports = [
    {
        module:  ...,
        name: 'build',
        externals: [
            new RegExp(`^library-package-name.*$`)
        ]
    },
    {
        module:  ...,
        name: 'dev-server',
    },
];

Options

packageName

Type: String Default: undefined

This is your package name that's will use in the generated path.

active

Type: Boolean Default: undefined

If you want to disabled the externals require and fallback on url-loader (a non production task for example)

extractCss

Type: Boolean Default: undefined

To generate a specific path for extracted css, if you use it with css-loader and MiniCssExtractPlugin during production process. You have to make a specific rule for css issuer and active this option.

It will generate a path like ~library-package-name/image.png

import img from './image.png';
// webpack.config.js
module.exports = {
    module: {
        rules: [
            {
                test: /\.(png||jpe?g|gif|svg)$/i,
                issuer: /\.(css|scss|less)$/i,
                use: [
                    {
                        loader: 'external-url-loader',
                        options: {
                            limit: 8192,
                            packageName: 'library-package-name', // your package name.
                            active: process.env.NODE_ENV === 'production', // if you want to enable or disable external-url-loader and fallback on url-loader.
                            extractCss: process.env.NODE_ENV === 'production', // if you want to enable or disable path generation for css extraction.
                        },
                    },
                ],
            },
            {
                test: /\.(png||jpe?g|gif|svg)$/i,
                issuer: /\.(js|jsx|ts|tsx)$/i,
                use: [
                    {
                        loader: 'external-url-loader',
                        options: {
                            limit: 8192,
                            packageName: 'library-package-name', // your package name.
                            active: process.env.NODE_ENV === 'production', // if you want to enable or disable external-url-loader and fallback on url-loader.
                        },
                    },
                ],
            },
        ],
    },
};

others:

All other options come from url-loader option

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT