Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add simple vite plugin #73

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

Closed
nojaf wants to merge 4 commits into rescript-lang:master from nojaf:vite-plugin
Closed

Conversation

Copy link
Member

@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.

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?

Copy link
Member 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.

Copy link
Member

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

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;

Copy link
Member 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.

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.

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.

Copy link
Member

cknitt commented Dec 13, 2024

@illusory0x0 Thanks! I will test that one.

@nojaf nojaf closed this Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@cknitt cknitt cknitt left review comments

@fhammerschmidt fhammerschmidt fhammerschmidt left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /