Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a dynamically assigned require function so that Clime can be used with Webpack #53

Open
booninite opened this issue Apr 2, 2019 · 3 comments

Comments

@booninite
Copy link

First, absolutely awesome library. It is everything I've ever wanted from a CLI framework after working with commander.js and oclif extensively.

I'm using your module with webpack, and the statements such as:

require(path);
require(possiblePath);

cause this package to break with webpack. I've successfully made it work locally by providing the following export from your internal-util directory:

// @ts-ignore
export const requireFoolWebpack = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require;

This allows the require statements to work correctly in webpack and non-webpack environments/bundles.

Would you be open to using something like this in place of require?

Cheers.

@vilicvane
Copy link
Owner

Hi, love to hear that you enjoy this library. Can you tell a little bit more on the scenario using webpack but not packing those command files?

It would be nice for Clime to support webpack, but why would people use webpack for dynamically loaded commands that are not going to be packed?

@booninite
Copy link
Author

I'm not against packing those files, but I found it straight-forward to have each command as an entry field on the webpack configuration, and then configuring output to ensure that each entry chunk is output in the same tree structure as the source for my CLI. I also intend on allowing users to install other clime based CLI as "plugins", which I think precludes bundling the different commands.

I was also considering initial bundle load size for large CLIs. I'd be interested in your thoughts on all of the above, though. These have just been my explorations in trying to provide a plugin-based CLI without using oclif.

@vilicvane
Copy link
Owner

I see. Actually one of the reasons that clime chose to have dynamically loaded commands is large CLI tools. I think exposing a configurable require function would be enough in this case, and it does look convenient to me considering not being a big addition.

Currently we have some configurable options related to module resolving on the constructor, such as commandModuleDefaultName, I think we can add a commandModuleRequire in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants