npm-install-webpack-plugin

Webpack loader to automatically npm install & save dependencies.

MIT 15 个版本
安装
npm install npm-install-webpack-plugin
yarn add npm-install-webpack-plugin
pnpm add npm-install-webpack-plugin
bun add npm-install-webpack-plugin
README

npm deps test coverage chat

NPM Install Webpack Plugin

Speed up development by automatically installing & saving dependencies with Webpack.

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 to install & save missing dependencies while you work!

Install

$ npm install --save-dev npm-install-webpack-plugin

Usage

In your webpack.config.js:

plugins: [
  new NpmInstallPlugin();
],

This is equivalent to:

plugins: [
  new NpmInstallPlugin({
    // Use --save or --save-dev
    dev: false,
    // Install missing peerDependencies
    peerDependencies: true,
    // Reduce amount of console logging
    quiet: false,
    // npm command used inside company, yarn is not supported yet
    npm: 'tnpm'
  });
],

You can provide a Function to the dev to make it dynamic:

plugins: [
  new NpmInstallPlugin({
    dev: function(module, path) {
      return [
        "babel-preset-react-hmre",
        "webpack-dev-middleware",
        "webpack-hot-middleware",
      ].indexOf(module) !== -1;
    },
  }),
],

Demo

npm-install-webpack-plugin mp4

Features

  • Works with both Webpack ^v1.12.0 and ^2.1.0-beta.0.
  • Auto-installs .babelrc plugins & presets.
  • Supports both ES5 & ES6 Modules. (e.g. require, import)
  • Supports Namespaced packages. (e.g. @cycle/dom)
  • Supports Dot-delimited packages. (e.g. lodash.capitalize)
  • Supports CSS imports. (e.g. @import "~bootstrap")
  • Supports Webpack loaders. (e.g. babel-loader, file-loader, etc.)
  • Supports inline Webpack loaders. (e.g. require("bundle?lazy!./App")
  • Auto-installs missing peerDependencies. (e.g. @cycle/core will automatically install rx@*)
  • Supports Webpack's resolve.alias & resolve.root configuration. (e.g. require("react") can alias to react-lite)

Maintainers


Eric Clemmons

Jonny Buchanan
版本列表
4.0.5 2017-08-17
4.0.4 2016-07-01
4.0.3 2016-06-14
4.0.2 2016-06-14
4.0.1 2016-06-07
4.0.0 2016-05-23
3.1.4 2016-05-20
3.1.3 2016-05-13
3.1.2 2016-05-12
3.1.1 2016-04-30
3.1.0 2016-04-25
3.0.0 2016-03-08
2.0.2 2016-01-31
2.0.1 2016-01-31
2.0.0 2016-01-24