alloc / cush

WIP module bundler 🎁
MIT License
0 stars 0 forks source link

cush.config.js #7

Closed aleclarson closed 6 years ago

aleclarson commented 6 years ago
// for javascript bundles only
exports.js = function() {
  this.plugin('markdown');    // enable .md modules
  this.plugin([ /* ... */ ]); // enable multiple plugins at once
  this.set('jsxPragma', 'h'); // use preact
  this.nebu.use([
    // nebu plugins goes here
  ]);
  console.log('dev:', this.dev);   // know if `this` is a development bundle
  console.log('root:', __dirname); // the project root
};

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's package.json if you want to activate them using this.plugin. You can use the file: 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. 😄

aleclarson commented 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.

aleclarson commented 6 years ago

The BundleConfig class will always have these methods:

...and these properties:

aleclarson commented 6 years ago

Implemented in d4025db59fc5e9267aadf31fdace98ab46d2e9c5 🎉