Closed aleclarson closed 6 years ago
The hook API:
this.hook('config', () => {
// Do something after `cush.config.js` has been applied.
});
// Provide a hook.
let hook = this.hook('my-hook');
hook.run(a, b, c);
The provider API may be expanded in the future. For example, the provider may want to run async hooks sequentially, instead of in parallel. Or the provider may want its hooks to have return values.
The BundleConfig
class will always have these methods:
get(path: string)
access a bundle optionset(path: string, value: any)
update a bundle optionplugin(name: string | string[])
activate a plugin or pluginshook(id: string, hook: ?function)
create a provider or hook into onehookModules(ext: string, hook: function)
hook into the module loaderhookPackages(hook: function)
hook into the package loader...and these properties:
dev: boolean
development modetarget: string
the targeted platformroot: string
the project root pathpack: object
the data from "package.json"Implemented in d4025db59fc5e9267aadf31fdace98ab46d2e9c5 đ
Since the exported function is called once per bundle, you may want to declare some variables outside if recreating them is costly, but I think that will be rare.
Bundle plugins must exist in the
devDependencies
of the project'spackage.json
if you want to activate them usingthis.plugin
. You can use thefile:
protocol to reference local plugins, if necessary.It might be cool to share this API with bundle plugins, so once you're familiar with bundle configuration, you're capable of making a bundle plugin, too! That would mean making this API a little more flexible by adding
this.hook
for package-loading and module-loading functions. Maybe bundle plugins could provide their own hooks, too!I'm open to suggestions on other capabilities. đ