返回介绍

NpmInstallWebpackPlugin

发布于 2019-05-27 04:54:34 字数 2997 浏览 936 评论 0 收藏 0

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!

安装

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

用法

webpack.config.js 中:

plugins: [
  new NpmInstallPlugin()
],

相当于

plugins: [
  new NpmInstallPlugin({
    // 使用 --save 或者 --save-dev
    dev: false,
    // 安装缺少的 peerDependencies
    peerDependencies: true,
    // 减少控制台日志记录的数量
    quiet: false,
    // npm command used inside company, yarn is not supported yet
    npm: 'tnpm'
  });
],

可以提供一个 Function 来动态设置 dev

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 demo

Features

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文