Many popular node packages support writing configuration files in JS or TS, like webpack
, vite
. Now I'm also trying to create a package supporting JS and TS configuration file, which would be used as: my-package --config path/to/config.ts
.
I first tried using require
directly, which failed for TS (that's quite an obvious result, since no loader for TS is specified).
So I then tried using typescript
package to transpile the config file and using require-from-string
to load the module, which doesn't work either when the specified config file import some other modules.
So my current problem is: how to get the configuration module resolved under current context.
Note that this package is designed to work like webpack-cli
, being added to devDependencies
by other packages and used as a tool for development. So the current context refers to the package that installs this package.
Here are some relative posts I've looked through and tried (so don't propose a duplicate to these questions):