Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ export default defineConfig({
output: './lib/js',
suffix: '.mjs',
},

// Control the terminal output of the ReScript compiler.
silent: false,

// Optionally add additional build args to the ReScript compiler.
// See https://rescript-lang.org/docs/manual/build-overview#compile-with-stricter-errors-in-ci
buildArgs: '-warn-error +32+27+26+110',
}),
],
});
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ type ReScriptProcess = {
async function launchReScript(
watch: boolean,
silent: boolean,
buildArgs: string,
): Promise<ReScriptProcess> {
const cmd = watch ? 'rescript watch' : 'rescript build';
let cmd = watch ? 'rescript watch' : 'rescript build';

if (buildArgs) {
cmd += ` ${buildArgs}`;
}

// https://github.com/rescript-lang/rescript/blob/9676953f5b5ce96ade6909af3f23a77cd69645e9/rewatch/src/watcher.rs#L246-L258
const finishSignal = 'Finished initial compilation';
Expand Down Expand Up @@ -71,6 +76,7 @@ interface Config {
suffix?: string;
};
silent?: boolean;
buildArgs?: string;
}

export default function createReScriptPlugin(config?: Config): Plugin {
Expand All @@ -83,6 +89,7 @@ export default function createReScriptPlugin(config?: Config): Plugin {
const suffix = config?.loader?.suffix ?? '.bs.js';
const suffixRegex = new RegExp(`${suffix.replace('.', '\\.')}$`);
const silent = config?.silent ?? false;
const buildArgs = config?.buildArgs ?? '';

return {
name: '@jihchi/vite-plugin-rescript',
Expand All @@ -106,7 +113,7 @@ export default function createReScriptPlugin(config?: Config): Plugin {
const watch = !isLocked && (command === 'serve' || Boolean(build.watch));

if (needReScript) {
childProcessReScript = await launchReScript(watch, silent);
childProcessReScript = await launchReScript(watch, silent, buildArgs);
}
},
config: (userConfig) => ({
Expand Down