How to exclude specs or test files from webpack build in TS project

If you have your spec files in your typescript project but not the actual test runner you might be getting some weird errors. This might happen if you have in a monorepo environment or some similar situation.

This error is actually good one because usually you shouldn’t have tests within your build.

The errors you might get could be something like this:

So to fix the situation and remove the errors you have to exclude the spec files from the build. This should be done through typescript configuration (tsconfig.json). With the following style:

Remember that exclude array defaults to these locations:
node_modules, bower_components, jspm_packages and .