Skip to content
Closed
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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,33 @@ If true, the plugin will use incremental compilation API introduced in typescrip
worker, but if the changes in your code are small (like you normally have when you work in 'watch' mode), the compilation
may be much faster, even compared to multi-threaded compilation. Defaults to `true` when working with typescript 3+ and `false` when below 3. The default can be overridden by directly specifying a value.

* **typescriptWatchMode** `string`:
This configures the watch mode of the Typescript compiler by passing the given `string` to
the [Typescript compiler watch mode configuration](https://www.typescriptlang.org/docs/handbook/configuring-watch.html).
The currently default mode of Typescript 3.4.x uses the [fs.watchFile()](https://nodejs.org/api/fs.html#fs_fs_watchfile_filename_options_listener)
of the `fs` module of `nodejs`, which is not efficient results on some systems to use up to ~10% of CPU usage when on idle.
This is not desirable for many reasons, therefore `fork-ts-checker-webpack-plugin` uses instead the `UseFsEventsWithFallbackDynamicPolling` configuration value
as a default that results in minimal CPU usage on idle and falls back to `DynamicPriorityPolling` on systems that do not support this.
The value can be any supported value of TS 3.4.x compiler for the `TSC_WATCHFILE` environment variable.
For convenience a pre-defined enumeration of strings that are supported by TS 3.4x is provided with `ForkTsCheckerWebpackPlugin.TypescriptWatchMode`.
More information and details about this can be found in the official [Typescript documentation of this option](https://www.typescriptlang.org/docs/handbook/configuring-watch.html).
Default: `ForkTsCheckerWebpackPlugin.TypescriptWatchMode.DEFAULT`;

* **measureCompilationTime** `boolean`:
If true, the plugin will measure the time spent inside the compilation code. This may be useful to compare modes,
especially if there are other loaders/plugins involved in the compilation. **requires node 8+**

* **typescript** `string`:
If supplied this is a custom path where `typescript` can be found. Defaults to `require.resolve('typescript')`.

### string consts of accepted values for TSC_WATCHFILE of Typescript Compiler:
* `ForkTsCheckerWebpackPlugin.TypescriptWatchMode.DEFAULT` - 'UseFsEventsWithFallbackDynamicPolling'
* `ForkTsCheckerWebpackPlugin.TypescriptWatchMode.PriorityPollingInterval` - 'PriorityPollingInterval'
* `ForkTsCheckerWebpackPlugin.TypescriptWatchMode.DynamicPriorityPolling` - 'DynamicPriorityPolling'
* `ForkTsCheckerWebpackPlugin.TypescriptWatchMode.UseFsEvents` - 'UseFsEvents'
* `ForkTsCheckerWebpackPlugin.TypescriptWatchMode.UseFsEventsWithFallbackDynamicPolling` - 'UseFsEventsWithFallbackDynamicPolling'
* `ForkTsCheckerWebpackPlugin.TypescriptWatchMode.UseFsEventsOnParentDirectory` - 'UseFsEventsOnParentDirectory'

* **resolveModuleNameModule** and **resolveTypeReferenceDirectiveModule** `string`:
Both of those options refer to files on the disk that respectively export a `resolveModuleName` or a `resolveTypeReferenceDirectiveModule` function. These functions will be used to resolve the import statements and the `<reference types="...">` directives instead of the default TypeScript implementation. Check the following code for an example of what those functions should look like:
<details>
Expand Down
30 changes: 29 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ interface Logger {
info(message?: any): void;
}

enum TypescriptWatchMode {
DEFAULT = 'UseFsEventsWithFallbackDynamicPolling',
PriorityPollingInterval = 'PriorityPollingInterval',
DynamicPriorityPolling = 'DynamicPriorityPolling',
UseFsEvents = 'UseFsEvents',
UseFsEventsWithFallbackDynamicPolling = 'UseFsEventsWithFallbackDynamicPolling',
UseFsEventsOnParentDirectory = 'UseFsEventsOnParentDirectory'
}

interface Options {
typescript: string;
tsconfig: string;
Expand All @@ -53,6 +62,7 @@ interface Options {
vue: boolean;
useTypescriptIncrementalApi: boolean;
measureCompilationTime: boolean;
typescriptWatchMode: TypescriptWatchMode;
resolveModuleNameModule: string;
resolveTypeReferenceDirectiveModule: string;
}
Expand Down Expand Up @@ -81,6 +91,8 @@ class ForkTsCheckerWebpackPlugin {
return getForkTsCheckerWebpackPluginHooks(compiler);
}

public static readonly TypescriptWatchMode = TypescriptWatchMode;

public readonly options: Partial<Options>;
private tsconfig: string;
private compilerOptions: object;
Expand All @@ -101,6 +113,7 @@ class ForkTsCheckerWebpackPlugin {
private colors: Chalk;
private formatter: Formatter;
private useTypescriptIncrementalApi: boolean;
private typescriptWatchMode: TypescriptWatchMode;
private resolveModuleNameModule: string | undefined;
private resolveTypeReferenceDirectiveModule: string | undefined;

Expand Down Expand Up @@ -225,6 +238,14 @@ class ForkTsCheckerWebpackPlugin {
? semver.gte(this.typescriptVersion, '3.0.0') && !this.vue
: options.useTypescriptIncrementalApi;

this.typescriptWatchMode =
options.typescriptWatchMode !== undefined
? options.typescriptWatchMode
: ForkTsCheckerWebpackPlugin.TypescriptWatchMode.DEFAULT;

// set the environment variable for the watch mode of typescript here
process.env.TSC_WATCHFILE = this.typescriptWatchMode.toString();

this.measureTime = options.measureCompilationTime === true;
if (this.measureTime) {
// Node 8+ only
Expand Down Expand Up @@ -662,7 +683,14 @@ class ForkTsCheckerWebpackPlugin {
) +
' with ' +
this.colors.bold(this.memoryLimit + 'MB') +
' memory limit'
' memory limit' +
' and ' +
(this.useTypescriptIncrementalApi === true
? this.colors.bold('Experimental TS Incremental API compilation') +
' in ' +
this.colors.bold(this.typescriptWatchMode) +
' watch mode'
: this.colors.bold('Normal Incremental compilation'))
);

if (this.watchPaths.length && this.isWatching) {
Expand Down