index-webpack-plugin v0.0.0
bundle-dependencies
Deprecated
The original benchmarks of bundledDependencies have been flawed.
To achieve the same result of bundle-dependencies using bundledDependencies package.json property:
- Add all
dependenciestobundledDependenciespackage.jsonproperty. - Before publishing, start in clean directory (i.e.,
rm -fr ./node_modules). - Install dependencies using
--productionflag (i.e.,npm install --production). - Publish package.
You can use bundled-dependencies package to automate the first step.
npm install bundled-dependencies --save-devAdd to package.json:
{
"scripts": {
"bundle-dependencies": "bundled-dependencies"
}
}Run:
npm run bundle-dependenciesbundle-dependencies
Bundles (deep) all module dependencies into a monolithic NPM package.
bundle-dependencies is designed to be used with devDependencies and modules installed using --global flag.
How much time can it save? Lets see.
2.3.63 release is done without bundle-dependencies.
time npm install pragmatist@2.3.63
34.59s user
6.15s system
24% cpu
2:44.35 total2.3.64 release is done with bundle-dependencies.
time npm install pragmatist@2.3.64
5.41s user
2.34s system
36% cpu
21.175 totalThe bundle-dependencies install process is 8 times faster (2 minutes 44 seconds compared to 21 second).
Usage
npm install bundle-dependencies --save-devAdd to package.json:
{
"scripts": {
"publish-bundle": "bundle-dependencies publish"
}
}To publish your package with bundled dependencies, run:
npm run publish-bundle.npmignore
Add to .npmignore (and .gitignore):
.backup.package.json
.backup.node_modulesThese are the backup files of your original ./package.json and ./node_modules. Do not commit them to the package registry.
Considerations
Implementation
bundle-dependencies publish execution flow is:
- Runs
bundle-dependenciesinternalprepublishlogic. - Executes
npm publish. - Runs
bundle-dependenciesinternalpostpublishlogic.
Do not add bundle-dependencies script to prepublish, publish or postpublish package.json scripts. NPM copies the contents of package.json before prepublish script is executed. This makes the internal prepublish logic impossible. prepublish and postpublish commands are exposed for testing only.
Internal prepublish logic.
- Backup the existing
./node_modules. - Backup the existing
./package.json. - Install package dependencies (
npm install --production). - Compress
./node_modulesto./bundled_modules.tar. - Remove all dependencies from
./package.json. - Add
bundled-dependenciesdependency to./package.json. - Add
postinstallscript to./package.json.
Internal postpublish logic.
- Delete
./bundled_modules.tar. - Delete
./package.json. - Restore the original
./node_modules. - Restore the original
./package.json.
postinstall script
The postinstall script is:
bundled-dependencies extract- Deletes
./node_modules. - Extracts
./bundled_modules.tarto./node_modules.
10 years ago