Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exported Class not included in the bundle if not used directly #158

Closed
bbottema opened this issue Feb 19, 2016 · 3 comments
Closed

Exported Class not included in the bundle if not used directly #158

bbottema opened this issue Feb 19, 2016 · 3 comments
Labels

Comments

@bbottema
Copy link

Maybe I'm going about it the wrong way, but I'm trying to convert a javascript project with Angular 1.x to WebPack and TypeScript. I got it mostly working, but I'm running into trouble when ts-loader seems to be optimizing my scripts out of the bundle when the exports are not directly used.

Here's a sample project demonstrating the issue (npm install, webpack, then load index.html). The logging from ClassA is showing up, but angular is reporting ClassB missing (provider). If you look in bundle.js you'll notice ClassB missing entirely.

https://github.com/bbottema/webpack-typescript

The difference is ClassA begin use directly after importing, and ClassB is only referenced by type for compilation.

Is there a way to force ClassB to be included? Or am I going about it wrong? Angular 2 would probably solve this issue, but that's a step too large right now.

@jbrantly
Copy link
Member

See this discussion and my answer on StackOverflow.

TypeScript elides unused modules by design. There are various discussions like here and here.

@bbottema
Copy link
Author

Thanks, I have a work around now. But it's not a pretty one (duplicate imports essentially).

I might use the preprocessor-loader to add an extra require for every typescript import it encounters. I'll give it a play and if it works, I'll report back.

@bbottema
Copy link
Author

I got it working using preprocessor that automatically insert require statements for import statements. My bundle is now produced properly without directly editing the source file.

The regex is rather limited however and needs some work to make it robust, but in concept it works.

microsoft/TypeScript#4717 (comment)

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

No branches or pull requests

2 participants