🍣 A Rollup plugin which automatically installs dependencies that are imported by a bundle, even if not yet in package.json.
This plugin requires an LTS Node version (v14.0.0+) and Rollup v1.20.0+.
Using npm:
npm install @rollup/plugin-auto-install --save-devCreate a rollup.config.js configuration file and import the plugin:
import auto from '@rollup/plugin-auto-install';
import resolve from '@rollup/plugin-node-resolve';
export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs'
},
plugins: [auto(), resolve()]
};Note: ensure that this plugin is added to the plugins array before @rollup/plugin-node-resolve.
Then call rollup either via the CLI or the API.
Type: String
Default: '{cwd}/package.json'
Specifies the location on disk of the target package.json file. If the file doesn't exist, it will be created by the plugin, as package managers need to populate the dependencies property.
Type: String
Default: see below
Specifies the package manager to use; npm or yarn. If not specified, the plugin will default to yarn if yarn.lock exists, or npm otherwise.
Thanks to Guillermo Rauch for the idea.