Skip to content

Commit

Permalink
Add new loader option "contextAsConfigBasePath", which when set to tr…
Browse files Browse the repository at this point in the history
…ue, parses to tsconfig file with respect to webpack context path (https://webpack.js.org/configuration/entry-context/#context) instead of the location of  the config file. So all relative paths in config file are treated relative to webpack context This makes configurations possible, where the tsconfig file is located in a npm package or elsewhere in the project structure.
  • Loading branch information
christiantinauer committed Nov 17, 2017
1 parent 013bac9 commit ebd2bb5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/config.ts
Expand Up @@ -116,12 +116,12 @@ function findConfigFile(compiler: typeof typescript, requestDirPath: string, con
export function getConfigParseResult(
compiler: typeof typescript,
configFile: ConfigFile,
configFilePath: string
basePath: string
) {
const configParseResult = compiler.parseJsonConfigFileContent(
configFile.config,
compiler.sys,
path.dirname(configFilePath || '')
basePath
);

return configParseResult;
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -139,6 +139,7 @@ function makeLoaderOptions(instanceName: string, configFileOptions: Partial<Load
logInfoToStdOut: false,
compiler: 'typescript',
configFile: 'tsconfig.json',
contextAsConfigBasePath: false,
transpileOnly: false,
compilerOptions: {},
appendTsSuffixTo: [],
Expand Down
6 changes: 5 additions & 1 deletion src/instances.ts
Expand Up @@ -71,7 +71,11 @@ function successfulTypeScriptInstance(

const { configFilePath, configFile } = configFileAndPath;

const configParseResult = getConfigParseResult(compiler, configFile, configFilePath!);
const basePath = loaderOptions.contextAsConfigBasePath
? loader.context
: path.dirname(configFilePath || '');

const configParseResult = getConfigParseResult(compiler, configFile, basePath);

if (configParseResult.errors.length > 0 && !loaderOptions.happyPackMode) {
const errors = formatErrors(configParseResult.errors, loaderOptions, colors, compiler, { file: configFilePath });
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Expand Up @@ -266,6 +266,7 @@ export interface LoaderOptions {
instance: string;
compiler: string;
configFile: string;
contextAsConfigBasePath: boolean;
transpileOnly: boolean;
ignoreDiagnostics: number[];
errorFormatter: (message: ErrorInfo, colors: Chalk) => string;
Expand Down

0 comments on commit ebd2bb5

Please sign in to comment.