Skip to content
This repository has been archived by the owner on Dec 1, 2019. It is now read-only.

Finding config file in a directory of the webpack entry resource #623

Open
maxxporoshin opened this issue Jan 16, 2019 · 1 comment
Open

Comments

@maxxporoshin
Copy link

maxxporoshin commented Jan 16, 2019

Hello guys!

Switched from ts-loader and run into inconvenience with typescript config files.

The problem is that config file is searched in the root directory for each entry despite its path.

The question is is it possible to make awesome-typescript-loader search config in the resource directory like ts-loader does?

Example:

Some directories in the project have their own tsconfig.json and each of them has corresponding entry point in the webpack config (or configs). To make awesome-typescript-loader use the right config, you have to specify config path for every entry which often means duplication of module/module.rules options.

Project structure:

dir1
--index1.ts
--tsconfig.json
dir2
--index2.ts
--tsconfig.json
index.ts
tsconfig.json
webpack.config.js

webpack.config.js:

module.exports = [{
    entry: { index: './index.ts' },
    module: {
         rules: [{
            test: /\.ts$/,
            loader: 'awesome-typescript-loader',
            options: {
                configFileName: './tsconfig.json',
            }
         }, ...]
    }
    ...
}, {
    entry: { index1: './dir1/index1.ts' },
    module: {
         rules: [{
            test: /\.ts$/,
            loader: 'awesome-typescript-loader',
            options: {
                configFileName: './dir1/tsconfig.json',
            }
         }, ...]
    }
    ...
}, {
    entry: { index2: './dir2/index2.ts' },
    module: {
         rules: [{
            test: /\.ts$/,
            loader: 'awesome-typescript-loader',
            options: {
                configFileName: './dir2/tsconfig.json',
            }
         }, ...]
    }
    ...
}];

Technically, this can be done with something like changing line

configFilePath = tsImpl.findConfigFile(context, tsImpl.sys.fileExists)

to

configFilePath = tsImpl.findConfigFile(webpack.resourcePath, tsImpl.sys.fileExists)

but is there any reason why this cannot / not intended to be done? I can open a PR myself if it's fine.

@MacKentoch
Copy link

MacKentoch commented Oct 10, 2019

Having same question.

My project sructure would be

front
--index1.ts
--tsconfig.json
server
--index2.ts
--tsconfig.json
index.ts

webpack.config.js

Trying to use configFileName but it does not work:

plugins: [
    new TsConfigPathsPlugin({
      configFileName: path.join(__dirname, '/front/tsconfig.json'),
    }),
...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants