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',
Copy link
Owner

Choose a reason for hiding this comment

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

It appears that -warn-error is incorrect. Could you please confirm?

$ ./node_modules/.bin/rescript --version
rescript 12.0.0

$ ./node_modules/.bin/rescript watch -warn-error +110
error: unexpected argument '-w' found

  tip: to pass '-w' as a value, use '-- -w'

Usage: rescript watch [OPTIONS] [FOLDER]

For more information, try '--help'.
Suggested change
buildArgs: '-warn-error +32+27+26+110',
buildArgs: '--warn-error +32+27+26+110',

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

Thank you for the link. I was aware of that section, but my concern is that it does not work for me with ReScript 12. I wonder if this is the case for other users with ReScript 12 who are using the example arguments.

}),
],
});
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