{"id":13496460,"url":"https://github.com/jihchi/vite-plugin-rescript","last_synced_at":"2025-05-16T18:08:55.796Z","repository":{"id":40576329,"uuid":"372187220","full_name":"jihchi/vite-plugin-rescript","owner":"jihchi","description":"Seamlessly integrate ReScript with Vite","archived":false,"fork":false,"pushed_at":"2025-05-05T13:30:52.000Z","size":1757,"stargazers_count":104,"open_issues_count":5,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-12T04:46:00.546Z","etag":null,"topics":["rescript","rescript-react","rollup-plugin","vite-plugin"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jihchi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-05-30T10:41:08.000Z","updated_at":"2025-04-28T17:01:35.000Z","dependencies_parsed_at":"2023-01-29T03:01:12.264Z","dependency_job_id":"e99dabbd-f60b-44cf-8cfd-5ddde0e38b53","html_url":"https://github.com/jihchi/vite-plugin-rescript","commit_stats":{"total_commits":215,"total_committers":8,"mean_commits":26.875,"dds":0.5534883720930233,"last_synced_commit":"ba0ba3d7298b42055fb543a41e29629874e244ac"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jihchi%2Fvite-plugin-rescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jihchi%2Fvite-plugin-rescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jihchi%2Fvite-plugin-rescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jihchi%2Fvite-plugin-rescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jihchi","download_url":"https://codeload.github.com/jihchi/vite-plugin-rescript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254582907,"owners_count":22095518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rescript","rescript-react","rollup-plugin","vite-plugin"],"created_at":"2024-07-31T19:01:48.204Z","updated_at":"2025-05-16T18:08:55.742Z","avatar_url":"https://github.com/jihchi.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# @jihchi/vite-plugin-rescript\n\n[![Workflows - CI][workflows-ci-shield]][workflows-ci-url]\n[![npm package][npm-package-shield]][npm-package-url]\n![npm download per month][npm-download-shield]\n[![npm license][npm-licence-shield]](./LICENSE)\n\nIntegrate ReScript with Vite by:\n\n- Starting ReScript compilation automatically\n- Showing HMR overlay for ReScript compiler errors\n- Importing `.res` files directly (see [Using Loader](#using-loader))\n\n## Getting Started\n\n\u003e If you are looking for a template to quickly start a project using Vite, ReScript and React, take a look at [vitejs-template-react-rescript](https://github.com/jihchi/vitejs-template-react-rescript), the template depends on this plugin.\n\n```sh\n# npm\nnpm i -D @jihchi/vite-plugin-rescript\n\n# yarn\nyarn add -D @jihchi/vite-plugin-rescript\n\n# pnpm\npnpm i -D @jihchi/vite-plugin-rescript\n```\n\nConfigure your vite plugin in `vite.config.ts`:\n\n```js\nimport { defineConfig } from 'vite';\nimport createReScriptPlugin from '@jihchi/vite-plugin-rescript';\n\nexport default defineConfig({\n  plugins: [createReScriptPlugin()],\n});\n```\n\nIf you're using `require` syntax:\n\n```js\nconst {\n  default: createReScriptPlugin,\n} = require('@jihchi/vite-plugin-rescript');\n```\n\n## Using Loader\n\nThe plugin comes with support for loading `.res` files directly. This is optional and in most cases not necessary,\nbut can be useful in combination with [\"in-source\": false](https://rescript-lang.org/docs/manual/latest/build-configuration#package-specs).\nWhen using `\"in-source\": false` (without the loader), importing local files using relative paths is troublesome.\nTake for example the following code:\n\n```res\n%%raw(`import \"./local.css\"`)\n@module(\"./local.js\") external runSomeJs: unit =\u003e unit = \"default\"\n```\n\nThe bundler will fail when reaching this file, since the imports are resolved relative to the generated JS file (which resides in `lib`),\nbut the `.css` and `.js` files are not copied into this directory. By utilizing the loader it no longer fails since the bundler will\nresolve the files relative to the `.res` file instead.\n\n### Configuration\n\nThe loader is configured to support `lib/es6` output with `.bs.js` suffix by default. This can be\nchanged by providing an options object to the plugin:\n\n```js\nexport default defineConfig({\n  plugins: [\n    createReScriptPlugin({\n      loader: {\n        output: './lib/js',\n        suffix: '.mjs',\n      },\n      silent: false,\n    }),\n  ],\n});\n```\n\n_Note: It is recommended to use `.bs.js` suffix since the loader cannot otherwise distinguish\nbetween imports of regular JS files and those that were generated by the ReScript compiler._\n\n_Note: Using es6-global module format may cause issues with imports of ReScript node modules,\nsince the paths to the node_modules will be generated as relative to the `lib` folder._\n\n### Setup\n\nFor HTML entry points, it must be imported using inline JS:\n\n```html\n\u003c!doctype html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\" /\u003e\n    \u003clink rel=\"icon\" type=\"image/svg+xml\" href=\"/favicon.svg\" /\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n    \u003ctitle\u003eVite App\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cdiv id=\"root\"\u003e\u003c/div\u003e\n    \u003cscript type=\"module\"\u003e\n      import '/src/Main.res';\n    \u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nIf using Vite with library mode, just use the `.res` as entry point:\n\n```js\nimport { defineConfig } from 'vite';\nimport createReScriptPlugin from '@jihchi/vite-plugin-rescript';\n\nexport default defineConfig({\n  plugins: [createReScriptPlugin()],\n  build: {\n    lib: {\n      entry: 'src/Main.res',\n    },\n  },\n});\n```\n\n## Contributors\n\nMany thanks for your help!\n\n\u003ca href=\"https://github.com/jihchi/vite-plugin-rescript/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=jihchi/vite-plugin-rescript\" /\u003e\n\u003c/a\u003e\n\nThe image of contributors is made with [contrib.rocks](https://contrib.rocks).\n\n[workflows-ci-shield]: https://github.com/jihchi/vite-plugin-rescript/actions/workflows/main.yml/badge.svg\n[workflows-ci-url]: https://github.com/jihchi/vite-plugin-rescript/actions/workflows/main.yml\n[npm-package-shield]: https://img.shields.io/npm/v/@jihchi/vite-plugin-rescript\n[npm-package-url]: https://www.npmjs.com/package/@jihchi/vite-plugin-rescript\n[npm-download-shield]: https://img.shields.io/npm/dm/@jihchi/vite-plugin-rescript\n[npm-licence-shield]: https://img.shields.io/npm/l/@jihchi/vite-plugin-rescript\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjihchi%2Fvite-plugin-rescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjihchi%2Fvite-plugin-rescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjihchi%2Fvite-plugin-rescript/lists"}