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

copy-browser-modules

v5.0.1

Published

A task to build browser dependencies out into a simple tree from node_modules packages

Downloads

466

Readme

Collects browser modules from node_modules and dumps them somewhere as commonjs Packages/A style packages (note that this is similar to but not the same as node modules), ready to use with requirejs.

First, it scans the tree of node_modules, detecting and erroring if browser modules overlap. There is no support for node style nesting dependencies and search path from each module.

Then it takes that list of modules and copies them to the target directory.

An example:

var copyBrowserTo = require('copy-browser-modules');

copyBrowserTo({ root: __dirname, basePath: 'public', dest: 'js/components'})
    .then(function() {
        console.log("Modules copied to 'public/js/components'")
    }).catch(function (err) {
        console.warn("An error occurred");
        console.warn(err.stack);
    });

The basePath is optional, but will allow you to adjust the location properties of the packages to match the view of the URL space as seen from the browser.

Module format

Modules are expected to end up in something approaching CommonJS Packages/A style. That means no nested dependencies, no node_modules, but package.json is still used. Because we're coopting the npm registry here, sometimes we need different information between the node and browser versions of things. If you put an browserPackage property in your package.json with a truthy value, the module will be considered browser-friendly. If that property is set to an object, the written package.json in the built tree will have these properties merged into the root and browserPackage left out.

This tool respects the files key, so a browser-only extract can be provided by providing an browserPackage.files property.

Note that dependencies are resolved before browserPackage merging is done, so dependency structure cannot vary between browser and non-browser packaging.

This package.json

{
    "name": "my-awesome-module",
    "version": "1.0.0",
    "files": [
        "test.js"
    ],
    "description": "Test",
    "browserPackage": {
        "files": [
            "browser.js"
        ]
    }
}

Will be written out as

{
    "name": "my-awesome-module",
    "version": "1.0.0",
    "files": [
        "browser.js"
    ],
    "description": "Test"
}

And the files copied will be browser.js not test.js.

Overrides

The package.json for your app can include a section like so:

    "browserPackage": {
        "overrides": {
            "packagename": {

which will be used as the browserPackage property for each package's package.json instead of what's there, allowing applications to use libraries that don't follow the convention yet despite shipping browser modules.

This is only supported at the root as this is not to be a convention for the consumption of others, but only used in the interim until the convention catches on for browser packages in the registry. Please make PRs against upstream package.json files!