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

node-modules-prod

v1.0.2

Published

prepare node_modules for production, convert symlinks, remove clutter

Downloads

383

Readme

node-modules-prod

prepare node_modules for production, convert symlinks, remove clutter

install

npm i node-modules-prod --save-dev

why

node_modules packages contain a lot of clutter, test folders, examples, documentation etc. Production site will never use them.
Small files containing just a few lines like .gitignore or .npmignore are taking a whloe allocation unit on a disk, that's why a 10Mb node_modules folder by size, may take 18Mb of disk space.
Local packages are stored as symbolic links in node_modules - great for development, but npm install on PROD will leave them as symbolic links, which will be broken once pushed to server.

This utility will:

  • convert symlink folders to actual folders
  • strip unneeded files and folders to bare minimum (Raspberry Pi friendly)
  • ignore packages listed as devDependencies

gulp use example

const copyNodeModules = require('node-modules-prod');

var dest = 'BUILD';

gulp.task('copy-node-modules', function(cb){

    copyNodeModules(
        './',        // sourceRoot relative to DEV root
        dest,        // destinationRoot relative to DEV root
        {},          // use default options
        cb           // callback for gulp task
    );
});

default options

quiet: true             // do not show progress in console, (progress shows only folder names)
logIgnored: false       // do not show ignored items in console (in magenta color)
noDevDependencies: true,// do not copy devDependencies (as per package.json)
useNpmignore: true,     // use npmignore file in each folder to exclude files
noIgnoreList: false,    // use ignore.js list
packageDir:'',          // dir name for package.json when not in dev root
logToFile: false        // for debugging, logfiles are created in LOG/ folder

NOTE:

The node-modules-prod only copies existing folders form DEV node_modules to BUILD folder.

  1. Run npm install in DEV, to make sure that all your dependencies in node_modules are in working order for target operating system!
  2. Make sure not to change default options to exclude unneeded folders and files from copying:
noDevDependencies: true, // do not copy devDependencies (form package.json)
useNpmignore: true,      // use npmignore file in each folder to exclude files
  1. If symlinks are in package.json, do NOT run npm install in BUILD folder!
  2. The node-modules-prod aggresively excludes unneeded files saving a lot of space. Excluded files can be listed in console (color cyan- excluded by npmignore, magenta - other than npmignore) with <- mark, by using logIgnored:true option. Exclusion list is in ignore.js file. Readme and License files are excluded too. Check licensing requirements for each package.

when node_modules and package.json is in a subfolder of dev root folder

  • do NOT append that subfolderName to dest
  • add options.packageDir=subfolderName to tell where to look for package.json otherwise devDependencies exclusion will not work.
const copyNodeModules = require('node-modules-prod');
var dest = 'BUILD';

gulp.task('copy-npm-modules', function(cb){

    copyNodeModules(
        './subfolderName',              // sourceRoot relative to DEV root
        dest,                           // destinationRoot relative to DEV root
        'node_modules',                 // dirName
        {                               // options:
            packageDir: 'subfolderName';// tell that package.json is in this subfolder
        }, 
        cb                              // callback for gulp task
    );
});

console

copying progress is shown in console with options {quiet:false} only folders are shown. (there are too many files to show) Additionally option {logIgnored: true} will show ignored files.

source -> destionation      // default color 
ignored <-                  // magenta {logIgnored:true}
symbolicLink => folder      // blue

debugging your build

use option {logToFile: true} to create file logs for copying operation. Folder LOG/ must exist in DEV root prior to running the task. Separate log files for excluded items will be created, for:

  • excluded-byCondition excluded because item is listed in devDependencies or in ignore.js list
  • excluded-byNpmignore excluded because items match .npmignore patterns.
    File .npmignore in some module may contain patterns that are not correctly interpreted by micromatch

aboul symbolic links

To check if you have symbolic links in node_modules, look for little link arrows on the folder icon in file explorer:

related: bower_components

to remove unneeded files and folders from bower_components try bower-purge.
Polymer 2 components are great! Don't bother with Polymer 3 (for C!# or C--).

requirements

NodeJS v8 and gulp v3 (tested on Win7)