<万博manbetx平台> NpmInstallWebpackPlugin - webpack 中文文档(v4.15.1) - 万博manbetx平台中文网
购物车
登陆 / 注册
微信扫码登陆

推荐手册

NpmInstallWebpackPlugin

通过使用Webpack自动安装和保存依赖项来加速开发。

仅仅为了安装一个直到现在你才知道你需要的依赖项,而尝试使用你的构建脚本和服务器是很糟糕的。

相反,使用“需要”或“导入”,通常情况下会自动进行NPM安装,以便在工作时安装并保存缺少的依赖项

安装

$ 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

1546397677(1).jpg

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)
网站导航
标签地图
学习路径
视频教程
开发软件
旗下子站
技术文章
文档工具
关于我们
企业合作
人才招聘
联系我们
讲师招募
QQ交流群
QQ官方交流群
微信公众号
微信公众号