ATTENTION: This repository is deprecated. See npm-install-webpack-plugin for way better alternative.
A Webpack plugin that automatically installs packages that contain your require'd modules.
Whenever Webpack resolves a requested module, the plugin first checks if the module is installed and then tries to install the corresponding package using npm.
For example, assuming the packages lodash.times is not currently installed, but you require it in your code like this:
var times = require("lodash.times");
times(5, function(i) {
console.log(i);
});
Running webpack
without using the plugin will result in an error because the module cannot be resolved. However, with the plugin enabled lodash.times
will be automatically installed without forcing you to go to your terminal and execute npm install lodash.times
.
Automatic installation of packages using the plugin should work in all language that are supported by the various Webpack loaders (such as loaders for Babel or Less).
npm install --save-dev auto-install-webpack-plugin
Just add an instance of AutoInstallPlugin to your plugins array.
var AutoInstallPlugin = require("auto-install-webpack-plugin");
module.exports = {
context: __dirname,
entry: "./index",
output: {
path: __dirname + "/build",
filename: "index.js"
},
plugins: [
new AutoInstallPlugin({save: true}),
],
};
You can pass a configuration object to the AutoInstallPlugin
constructor. The following keys and values are recognized:
save
:true
(default) if the plugin should--save
the installed package,false
otherwise.
I appreciate any kind of feedback. Just create an issue or drop me a mail. Thanks!
See LICENSE.