npm-install-loader
Version:
Webpack loader to automatically npm install & save dependencies.
77 lines (55 loc) • 2.03 kB
Markdown
# npm-install-loader
> Webpack loader to automatically npm install & save dependencies.
[](https://travis-ci.org/ericclemmons/npm-install-loader)
[](https://coveralls.io/github/ericclemmons/npm-install-loader?branch=master)
[](http://npm.im/npm-install-loader)
[](http://npm-stat.com/charts.html?package=npm-install-loader)
[](http://opensource.org/licenses/MIT)
- - -
### Why?
It sucks to <kbd>Ctrl-C</kbd> 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`:
```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:
```ini
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`:
```js
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