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

How to exclude certain paths from awesome-typescript-loader only? #359

Closed
rfgamaral opened this issue Jan 29, 2017 · 10 comments
Closed

How to exclude certain paths from awesome-typescript-loader only? #359

rfgamaral opened this issue Jan 29, 2017 · 10 comments
Assignees

Comments

@rfgamaral
Copy link

I have an "app" and "tests" folders on the root of my project and I need to exclude the "tests" folder from awesome-typescript-loader. There doesn't seem to be an option for that on the loader...

This is my current tsconfig.json file that is currently used by awesome-typescript-loader by default:

{
    "compilerOptions": {
        "sourceMap": true,
        "removeComments": true,
        "noImplicitAny": true,
        "preserveConstEnums": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "module": "commonjs",
        "target": "es5",
        "jsx": "react"
    }
}

One way to achieve what I want is to add an exclude array to the tsconfig.json above but that's not good because then Sublime Text (and I've also tried with Visual Studio Code) will not recognize anything when I open one of my .ts files inside the "tests" folder.

In other words, I need to exclude the "tests" folder only from awesome-typescript-loader, not globally. AFAIK, awesome-typescript-loader only allows one to override the compilerOptions section of the tsconfig.json file, not the other root properties like files, include or exclude.

What can I do to achieve this?

@rfgamaral
Copy link
Author

Perhaps a better question would be why are files under the "tests" folder being loaded at all?

I mean, in my webpack configuration I have a single entry point file for my app. From this file, the imports will include all other required modules to make my app work. No file inside the "app" folder is importing a module in the "tests" folder. So, why are the files under "tests" being loaded!?

@TheKeithStewart
Copy link

@rfgamaral I believe that the reason that your tests folder is being loaded is because the source of the files that are being processed is not coming from webpack it is coming from TypeScript via your tsconfig.json file. To exclude your tests directory what you can do is add an exclude section to your tsconfig.json file. It would look something like this:

{
    "compilerOptions": {
        "sourceMap": true,
        "removeComments": true,
        "noImplicitAny": true,
        "preserveConstEnums": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "module": "commonjs",
        "target": "es5",
        "jsx": "react"
    },
    "exclude": [
        "node_modules",
        "tests"
    ]
}

@rfgamaral
Copy link
Author

@kgs916 But should they? I really thought that the files loaded by Webpack were only the ones referenced as an entry point (and the ones referenced by those). I guess I was wrong.

I tried that exclude in tsconfig.json approach but that doesn't work so well with editors, at least with Sublime Text or Visual Studio Code. What happened was that opening any file inside the "tests" folder would give a bunch of reference errors inside the editor. The project would still compile and my tests still run, it's just the editors that don't seem to like the exclude option.

Am I doing something wrong here or I'm the only one trying to exclude test files in tsconfig.json? Should I even be bothered with this?

Thanks for your response :)

@TheKeithStewart
Copy link

@rfgamaral I agree, makes more sense for the files affected to only include the ones being handled by webpack. Sounds like a good candidate for a PR.

In the mean time, you could have a separate tsconfig file that is only by this loader. So, the editors would continue using tsconfig.json without the exclude of tests and you would have tsconfig.webpack.json that would have the exclude statement. The README here mentions a couple ways that you can specify which tsconfig file is used. I'm not completely clear about how it would look but it looks like it is possible.

@s-panferov
Copy link
Owner

Closed in favour of #364

@rfgamaral
Copy link
Author

Thank you for taking the time dealing with this issue and the suggestion :)

@damonsmith
Copy link

I was looking at this issue because we have a build that uses ts-loader, I thought I'd try out atl but it was picking up our /src/custom-type-definitions folder even though it's excluded in tsconfig.json and it isn't used by any code (we npm include them into node_modules/@types/ and use them from there. So atl is picking up definitions from all over the codebase, regardless of location or exclusion.

Is that expected behaviour? Does ATL just scan the entire rootDir for *.d.ts?

@s-panferov
Copy link
Owner

@damonsmith no, ATL just uses internal TypeScript machinery to resolve files. Please make sure that your have correct exclude and that your project type-checks with pure tsc

@winston01
Copy link

winston01 commented Oct 18, 2017

This may be useful for some: how to make ATL check only those files that are referenced:

https://stackoverflow.com/questions/43234525/awesome-typescript-loader-load-compile-only-refrenced-files

TL;DR: set files parameter as empty array ("files": []) in the config file of ATL.

@DmitryMaksakov
Copy link

@winston01, this approach doesn't work with webpack 3.10.0 and awesome-typescript-loader 3.4.1.
ATL for some reason includes all files rather than include only refferenced.

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

No branches or pull requests

6 participants