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

EsBuild suport #463

Open
ffind opened this issue Apr 2, 2023 · 1 comment
Open

EsBuild suport #463

ffind opened this issue Apr 2, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@ffind
Copy link

ffind commented Apr 2, 2023

Is your feature request related to a problem? Please describe.
I'm using esbuild stack, ie vite, vitests and wanted to setup mocks-server without babel, but as far as I understood it is not really possible

Describe the solution you'd like
Would be nice to avoid strict binding to certain transpiler, may be to have set of plugins that allow typescript support? I'm glad to support

@javierbrea
Copy link
Member

Hi @ffind,
For the moment the only possibility for doing such thing is developing a plugin and loading files from a folder different to the "mocks" one.

The server is made with CJS, and it requires a transpiler for converting files in any other format to it before loading them. Converting the files in the "mocks" folder is a responsibility of an element in the core of the server, so, this behavior can't be modified by using a plugin. The server API includes a files.createLoader method that allows to receive file contents from defined folders in the "mocks" path, and implement your own customized behavior when files are loaded or they change, but file contents are received already transpiled in this case, so this method is not valid for your requirement.

So, as mentioned, you could implement a plugin being at charge of loading files from a different folder at your convenience, and then use the mock.createloaders method for adding routes and collections based on their contents. But you would have to implement the whole logic about reading the files and transpile them with your preferred library, and you would be also at charge of watching the files in order to refresh the routes and collections when there is any change, convert YAML files, etc.

The good new is that currently I'm migrating the project to TypeScript, and I'll try to export the project both in CJS and ESM, so, probably in next releases ESM would be supported out of the box, without the need to use any transpiler. But it would be still needed to transpile TypeScript files, so I will take this requirement into account in order to provide also an easier mechanism to use custom transpilers.

@javierbrea javierbrea added the enhancement New feature or request label Apr 7, 2023
@javierbrea javierbrea moved this to To do in Backlog May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: To do
Development

No branches or pull requests

2 participants