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

Add simple vite plugin #73

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

nojaf
Copy link
Contributor

@nojaf nojaf commented Aug 29, 2024

I'd propose to streamline the experience by running a single command to start the Vite dev server.
I've added a simple plugin that will start the ReScript process as part of the vite pipeline.

Just type npm run dev (the default vite experience) and start hacking.

(I've also updated the npm packages)

@fhammerschmidt let me know what you think.

@fhammerschmidt
Copy link
Member

There is a bit of a trade-off between keeping a template as simple and transparent as possible and making it easy to get started. I am concerned that your plugin will break in subtle ways with vite or its react plugin as was sometimes the case already. Does fast refresh work?

@nojaf
Copy link
Contributor Author

nojaf commented Aug 29, 2024

All works as before. It is a slight trade-off in terms of transparency.
However, I wouldn't underestimate how many devs are used to running the single command to get going.

Comparing it with Vite and TypeScript:

bun create vite
✔ Project name: … some-ts-project
✔ Select a framework: › React
✔ Select a variant: › TypeScript

Scaffolding project in /home/nojaf/projects/some-ts-project...

Done. Now run:

  cd some-ts-project
  bun install
  bun run dev

I update the tsx file and expect to see my browser reflect the change.
Which is what happens as well with this plugin.

@fhammerschmidt
Copy link
Member

I am still indifferent, what do you think @cknitt or @zth?

@cknitt
Copy link
Member

cknitt commented Nov 30, 2024

@nojaf Sorry for the late feedback, somehow missed this before.

It certainly makes for a nicer experience, especially for someone new to ReScript.

Two concerns:

  1. How dependent is this solution on the Vite version? E.g., does it still work with Vite 6? Do you think we should update the template to Vite 6 already?
  2. Colors in the ReScript output are lost, this is a bit of a downside.

* @returns Vite plugin
*/
function rescript() {
let rescriptProcressRef = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let rescriptProcressRef = null;
let rescriptProcessRef = null;

@nojaf
Copy link
Contributor Author

nojaf commented Nov 30, 2024

  1. How dependent is this solution on the Vite version? E.g., does it still work with Vite 6? Do you think we should update the template to Vite 6 already?

This is unaffected in by the Vite 6 major, their plugin model is pretty stable. This will continue to keep on working. I have upgraded some of my projects to Vite 6, we should do it, this release was more significant for frameworks rather than end users.

  1. Colors in the ReScript output are lost, this is a bit of a downside.

Hmm, yes, I'm not sure if that can easily be resolved.

@cknitt
Copy link
Member

cknitt commented Nov 30, 2024

Regarding colors, I just tried this and it works:

      const env = { ...process.env, FORCE_COLOR: "1", NINJA_ANSI_FORCED: "1" };
      if (command === "build") {
        logger.info(execSync("rescript", { env }).toString().trim());
      } else {
        rescriptProcressRef = spawn("rescript", ["-w"], { env });
        logger.info(`Spawned rescript -w`);

But there is another remaining problem here: In the build/execSync case, if there is a compilation error, the output from the rescript process is not logged.

@illusory0x0
Copy link

@cknitt I found other vite-plugin-rescript https://github.com/jihchi/vite-plugin-rescript, it can add simply and like vite can load .ts file, this plugin can load .res files, rather than res.mjs as before

The plugin comes with support for loading .res files directly.

@cknitt
Copy link
Member

cknitt commented Dec 13, 2024

@illusory0x0 Thanks! I will test that one.

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

Successfully merging this pull request may close these issues.

4 participants