webpack: Webpack unexpectedly watches unrelated files even the ones not imported anywhere
Bug report
What is the current behavior?
Webpack in watch mode is recursively scanning unrelated files in the current working directory and the src
folder even though none of them should appear in the dependency graph and they don’t happen to be imported in any of the files defined by the entry
config.
The result is that even though those files don’t end up in the bundle, webpack still attempts to process them and (re)builds take an enormous amount of time since it aparently works on the dependency graph on the “94% after seal” step.
I noticed this issue due to immense build times and because I had some TypeScript errors in certain files in the src
folder which all of a sudden appeared in the webpack output even though those files are unrelated to the entry file!
If the current behavior is a bug, please provide the steps to reproduce.
Create a simple foo.ts
file in your root folder and have a src
folder with an arbitrary amount of source files. In our case this was our entire codebase. The foo.ts
file should only contain console.log("Foo");
. Run webpack in watch mode with the following config file:
const path = require('path');
module.exports = {
entry: './foo.ts',
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: [
/node_modules/
]
}
]
},
resolve: {
extensions: [ '.tsx', '.ts', '.js' ]
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
};
What is the expected behavior?
The bundle will only contain the foo.ts
output and be built in merely milliseconds instead of 10+ seconds with our huge codebase in the mentioned src
folder.
Other relevant information: webpack version: 4.29.6 Node.js version: 8.10.0 Operating System: macOS 10.14.4 Additional tools: n/a
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 21 (9 by maintainers)
Do you experience the same if you’re using the
fork-ts-checker-webpack-plugin
? Example setup here: https://github.com/TypeStrong/ts-loader/tree/master/examples/fork-ts-checker-webpack-pluginSomebody can create minimum reproducible test repo? Looks like problem in
ts-loader