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

Loader emits unnecessary dependencies to compilation #351

Closed
colinskow opened this issue Jan 14, 2017 · 3 comments
Closed

Loader emits unnecessary dependencies to compilation #351

colinskow opened this issue Jan 14, 2017 · 3 comments
Labels

Comments

@colinskow
Copy link

colinskow commented Jan 14, 2017

Expected behavior: the loader should only emit files actually in the module (or reference) dependency tree as file dependencies to Webpack.

Actual behavior: the loader emits every single TypeScript file in the project as a dependency regardless of the entries. This can cause performance problems in watch mode.

I have one entry which is a TypeScript file with no dependencies, and at-loader is emitting hundreds of files for Webpack to watch. In my use case I am building an electron app with separate builds for the main and renderer processes. When a dependency of main changes I want to restart the main process, and when a dependency of the renderer changes I want to refresh the browser. Right now this impossible because at-loader causes Webpack to watch every single .ts file in the project, including node_modules.

I tracked the offending code down to src/instance.ts#L368:

Array.prototype.push.apply(compilation.fileDependencies, files.map(path.normalize));

When I comment out this line the loader behaves as expected and only files from the actual dependency tree of the entries are added to the Webpack compilation as dependencies.

The correctly needed dependencies are added here, and the code above in instance.ts is wasteful and unnecessary.

@colinskow
Copy link
Author

OK, I realized there is a fatal flaw in this approach that lazy loaded modules (such as from Angular 2) don't get emitted as dependencies in this scenario.

I think a better solution is to probably specify the exact entry files that need to be parsed under "files" in tsconfig.json. This way the TypeScript compiler doesn't parse anything unnecessary.

@colinskow
Copy link
Author

What I need to resolve this issue is a way to pass in a list of filenames, which will be merged into the tsconfig.json as files.

Furthermore, it would be nice to be able to pass the loader an object which will be merged on top of the contents of tsconfig.json. I saw there is a configFileContent options available in instance.ts but it didn't work as expected.

@s-panferov
Copy link
Owner

Closed in favour of #364

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

No branches or pull requests

2 participants