Adds loader options support to tsoverlay (#251)

* adding loaderoptions for tsoverlay

* Change files

* adding support for the LoaderOptions for tsoverlay

* gotta love typescript
This commit is contained in:
Kenneth Chau 2019-09-27 10:03:17 -07:00 коммит произвёл GitHub
Родитель 6193364e35
Коммит 9b93f584f3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 96 добавлений и 22 удалений

Просмотреть файл

@ -0,0 +1,8 @@
{
"type": "minor",
"comment": "adding loaderoptions for tsoverlay",
"packageName": "just-scripts",
"email": "odbuild@microsoft.com",
"commit": "bcb1f45b53956000e9fe03e6eff84c1f27d9375a",
"date": "2019-09-27T16:25:11.131Z"
}

Просмотреть файл

@ -7,7 +7,7 @@ export * from './webpack/webpack.config';
export * from './webpack/webpack.serve.config'; export * from './webpack/webpack.serve.config';
// Webpack configs and overlays // Webpack configs and overlays
import { tsOverlay } from './webpack/overlays/tsOverlay'; import { tsOverlay, TsCheckerOptions, TsLoaderOptions } from './webpack/overlays/tsOverlay';
import { htmlOverlay } from './webpack/overlays/htmlOverlay'; import { htmlOverlay } from './webpack/overlays/htmlOverlay';
import { stylesOverlay, createStylesOverlay } from './webpack/overlays/stylesOverlay'; import { stylesOverlay, createStylesOverlay } from './webpack/overlays/stylesOverlay';
import { fileOverlay } from './webpack/overlays/fileOverlay'; import { fileOverlay } from './webpack/overlays/fileOverlay';
@ -21,7 +21,16 @@ export const webpackOverlays = {
displayBailout: displayBailoutOverlay displayBailout: displayBailoutOverlay
}; };
export { tsOverlay, htmlOverlay, stylesOverlay, fileOverlay, displayBailoutOverlay, createStylesOverlay }; export {
tsOverlay,
htmlOverlay,
stylesOverlay,
fileOverlay,
displayBailoutOverlay,
createStylesOverlay,
TsCheckerOptions,
TsLoaderOptions
};
import webpackMerge from 'webpack-merge'; import webpackMerge from 'webpack-merge';
export { webpackMerge }; export { webpackMerge };

Просмотреть файл

@ -1,8 +1,66 @@
import ts from 'typescript';
import { tryRequire } from '../../tryRequire'; import { tryRequire } from '../../tryRequire';
const ForkTsCheckerPlugin = tryRequire('fork-ts-checker-webpack-plugin'); const ForkTsCheckerPlugin = tryRequire('fork-ts-checker-webpack-plugin');
export const tsOverlay = () => ({ export interface TsLoaderOptions {
configFile: string;
transpileOnly: boolean;
onlyCompileBundledFiles: boolean;
colors: boolean;
compilerOptions: ts.CompilerOptions;
happyPackMode: boolean;
getCustomTransformers: string | ((program: ts.Program) => ts.CustomTransformers | undefined);
experimentalWatchApi: boolean;
allowTsInNodeModules: boolean;
experimentalFileCaching: boolean;
projectReferences: boolean;
}
export interface TsCheckerOptions {
typescript: string;
tsconfig: string;
compilerOptions: object;
tslint: string | true | undefined;
tslintAutoFix: boolean;
eslint: true | undefined;
/** Options to supply to eslint https://eslint.org/docs/1.0.0/developer-guide/nodejs-api#cliengine */
eslintOptions: object;
watch: string | string[];
async: boolean;
ignoreDiagnostics: number[];
ignoreLints: string[];
ignoreLintWarnings: boolean;
reportFiles: string[];
colors: boolean;
silent: boolean;
checkSyntacticErrors: boolean;
memoryLimit: number;
workers: number;
vue: boolean;
useTypescriptIncrementalApi: boolean;
measureCompilationTime: boolean;
resolveModuleNameModule: string;
resolveTypeReferenceDirectiveModule: string;
}
export interface TsOverlayOptions {
loaderOptions?: Partial<TsLoaderOptions>;
checkerOptions?: Partial<TsCheckerOptions>;
}
export const tsOverlay = (overlayOptions?: TsOverlayOptions) => {
overlayOptions = overlayOptions || {};
overlayOptions.loaderOptions = overlayOptions.loaderOptions || {
transpileOnly: true
};
overlayOptions.checkerOptions = overlayOptions.loaderOptions || {
transpileOnly: true
};
return {
resolve: { resolve: {
extensions: ['.wasm', '.mjs', '.js', '.ts', '.tsx', '.json'] extensions: ['.wasm', '.mjs', '.js', '.ts', '.tsx', '.json']
}, },
@ -12,13 +70,12 @@ export const tsOverlay = () => ({
test: /\.tsx?$/, test: /\.tsx?$/,
use: { use: {
loader: 'ts-loader', loader: 'ts-loader',
options: { options: overlayOptions.loaderOptions
transpileOnly: true
}
}, },
exclude: /node_modules/ exclude: /node_modules/
} }
] ]
}, },
plugins: [...(ForkTsCheckerPlugin ? [new ForkTsCheckerPlugin()] : [])] plugins: [...(ForkTsCheckerPlugin ? [new ForkTsCheckerPlugin(overlayOptions.checkerOptions)] : [])]
}); };
};