Skip to content

Commit

Permalink
Documentation for afterEmit plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Perryvw committed Nov 20, 2023
1 parent 5f1ddce commit 7e47643
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/api/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ const plugin: tstl.Plugin = {
export default plugin;
```

### `afterEmit`

The `afterEmit` function is called after all output files have been written to disk. This might be useful if you need to somehow post-process the output Lua, for example by feeding it to a Lua minifier.

```ts
import * as ts from "typescript";
import * as tstl from "typescript-to-lua";

const plugin: tstl.Plugin = {
afterEmit(program: ts.Program, options: tstl.CompilerOptions, emitHost: tstl.EmitHost, result: tstl.EmitFile[]) {
for (const emittedFile of result) {
console.log(`Emitted file ${emittedFile.outputPath}`);
}
},
};

export default plugin;
```

### `moduleResolution`

You can use the `moduleResolution` function to modify how the tstl module resolution works. It provides you with the require path, the file requiring that module, the tsconfig options used to compile the project, and the tstl EmitHost.
Expand Down

0 comments on commit 7e47643

Please sign in to comment.