59 | 🙋 What does the patch do?
60 | It allows Remix to transpile ES modules (export/import syntax) inside of node_modules. This is important because our ReScript configuration tells the compiler to transpile to ESM, and this includes ReScript dependencies in node_modules eg. this package and the ReScript standard library.
61 |
62 |
63 | ### Enable transpilation of ESM modules
64 |
65 | Add `"rescript"` to the `transpileModules` option in `remix.config.js`. This ensures that our patch installed above will transpile the ReScript standard library.
66 |
67 | ```diff
68 | /**
69 | * @type {import('@remix-run/dev/config').AppConfig}
70 | */
71 | module.exports = {
72 | appDirectory: "app",
73 | assetsBuildDirectory: "public/build",
74 | publicPath: "/build/",
75 | serverBuildDirectory: "build",
76 | devServerPort: 8002,
77 | ignoredRouteFiles: [".*", "*.res"],
78 | + transpileModules: ["rescript"],
79 | };
80 | ```
81 |
82 | You'll need to add more packages to this array whenever you receive a Remix error message that says it failed to compile ESM syntax. This is often the case when you install a new ReScript dependency.
83 |
84 | ### Enable convention based routing for ReScript modules
85 |
86 | Add a `routes` option to `remix.config.js` and inside call the `registerRoutes` function exported by `rescript-remix/registerRoutes`:
87 |
88 | ```diff
89 | + const { registerRoutes } = require('rescript-remix/registerRoutes');
90 |
91 | /**
92 | * @type {import('@remix-run/dev/config').AppConfig}
93 | */
94 | module.exports = {
95 | appDirectory: "app",
96 | assetsBuildDirectory: "public/build",
97 | publicPath: "/build/",
98 | serverBuildDirectory: "build",
99 | devServerPort: 8002,
100 | ignoredRouteFiles: [".*", "*.res"],
101 | transpileModules: ["rescript"],
102 | + routes(defineRoutes) {
103 | + return defineRoutes(route => {
104 | + registerRoutes(route);
105 | + });
106 | + }
107 | };
108 | ```
109 |
110 | This allows you to use all of the convention-based routing of Remix with ReScript modules by placing them inside the `app/res-routes` director. See [the usage section](#convention-based-routing) for more details.
111 |
112 | ### (optional) Git ignore compiled JS
113 |
114 | JS is outputted alongside ReScript modules to enable convention based routing. You can opt to not commit these build artifacts by adding the following lines to `.gitignore`:
115 |
116 | ```
117 | /app/**/*.jsx
118 | /app/**/*.js
119 | ```
120 |
121 | This step is optional as it's personal preference. Some people prefer to check in the artifacts generated by ReScript to enable teammates that aren't familiar with the language to make quick changes, or to ensure the output from the compiler is as expected.
122 |
123 | ## Adopting into an existing Remix app
124 |
125 | todo
126 |
127 | ## Usage
128 |
129 | todo
130 |
131 | ### Convention based routing
132 |
133 | todo
134 |
--------------------------------------------------------------------------------
/__tests__/MockFs.res:
--------------------------------------------------------------------------------
1 | @module external mock: {..} => unit = "mock-fs"
2 | @module external mockWithDict: Js.Dict.t<'a> => unit = "mock-fs"
3 |
4 | @module("mock-fs") external restore: unit => unit = "restore"
5 |
--------------------------------------------------------------------------------
/__tests__/RouteConventions_spec.res:
--------------------------------------------------------------------------------
1 | // Disable warning on unused parameter (required by the raw JS)
2 | @@warning("-27")
3 |
4 | open Jest
5 | open Expect
6 |
7 | module Map = Belt.MutableMap.String
8 |
9 | type rec routeDefinition = {file: string, nested: option