aleclarson / cara

UNMAINTAINED - see https://github.com/aleclarson/cush
MIT License
0 stars 0 forks source link

On-demand plugin install #3

Closed aleclarson closed 6 years ago

aleclarson commented 6 years ago

Include plugin detection within src/plugins/*.js files, paired with which NPM package should be installed (global cache?) when a bundle needs the plugin.

Right now, the Babel, TypeScript, and SASS plugins are installed automatically, which is not ideal.

aleclarson commented 6 years ago

The initial implementation is in place (see here).

The plugins themselves are included in the core, but their heavy dependencies are installed on-demand (when a bundled package needs the plugin).

This can be used by third-party plugins like so:

import {lazyRequire} from 'cara/utils'
import {Plugin} from 'cara'

class MyPlugin extends Plugin {
  async load() {
    this._transform = await lazyRequire('my-transformer')
  }

  transform(module) {
    return this._transform(module.read())
  }
}