U-Day
U-Day

Reputation: 93

Javascript: Webpack+Typescript+Namespace (internal module)

We are trying to use Webpack to compile typescript code where we replaced “module” (now defined as external modules) with namespaces (defined as internal modules).

This change was done primarily to be in line with the recommendations of typescript and ensuring that dependency on “require” is not required for running Jasmine based unit tests on Karma. Karma-typescript preprocessor has been configured and the test case is running fine without the need of "require".

The change to namespace caused us to remove the dependency on require which works very well when it comes unit tests and compilation of the code through tsc. But on compilation through Webpack using typescript loaders (I’ve tried ts-loader, Webpack-typescript), the output contains code of just the entry ts file and not its dependencies. Tsc already has an option (--outFile) to concatenate the output into a single file but both the loaders do not use it.

Is there a way (loader or configuration of a loader) to resolve the dependency and bundle it into the single output js produced by Webpack?

Upvotes: 6

Views: 2251

Answers (1)

basarat
basarat

Reputation: 276209

This change was done primarily to be in line with the recommendations of typescript and ensuring that dependency on “require” is not required for running Jasmine based unit tests on Karma

You don't need to do that. You should use --module:commonjs everywhere and bundle for frontend + leave it as it is for running tests using node (node understands commonjs natively).

Example

I do this with alm https://github.com/alm-tools/alm/

Upvotes: 1

Related Questions