npm-install-loader
v1.1.1
Published
Webpack loader to automatically npm install & save dependencies.
Downloads
21
Maintainers
Readme
npm-install-loader
Webpack loader to automatically npm install & save dependencies.
Why?
It sucks to Ctrl-C your build script & server just to install a dependency you didn't know you needed until now.
Instead, use require
or import
how you normally would and npm install
will happen automatically install missing dependencies between reloads.
Usage
In your webpack.config.js
:
module: {
postLoaders: [
{
exclude: /node_modules/,
loader: "npm-install-loader",
test: /\.js$/,
},
],
}
This will ensure that any other loaders
(e.g. eslint-loader
, babel-loader
, etc.) have completed.
Saving
This loader simply runs npm install [modules]
.
I recommend creating an .npmrc
file
in the root of your project with:
save=true
This will automatically save any dependencies anytime you run npm install
(no need to pass --save
).
Alternatively, you can provide CLI arguments that get added directly to npm install
:
postLoaders: [
{
exclude: /node_modules/,
loader: "npm-install-loader",
query: {
cli: {
registry: "..." // --registry='...'
save: true, // --save
saveExact: true, // --save-exact
},
},
test: /\.js$/,
},
],
### License
> MIT License 2015 © Eric Clemmons