shlomiassaf / ng-router-loader

Webpack loader for NgModule lazy loading using the angular router
MIT License
46 stars 8 forks source link

adding tsConfigDir option, so modules can be resolve relative to the path of the tsconfig file #6

Open vlavella opened 7 years ago

vlavella commented 7 years ago

I found that in complex folder structures the path of the modules is not resolved well for lazy loading routes.

This is how my folder structure looks like:

      code 
       |___ client_src
       |            |___ aot_folder
       |            |___ app_folder
       |            |___ tsconfig.client.json
       |
       |____ server_src
       |            |___tsconfig.server.json
       |___webpack-config.js

I need webpack to use the tsconfig.client.json to compile AOT and need to have that hierarchy of directories. The issue is that webpack is trying to resolve the modules from the current process directory (is assuming that the ts.config is located there) so is not able to get the relative path of the modules correctly.

I added a new option in order to set the location of the tsconfig.If you don't set that option the loader will assume that the file is located in the current process directory (same as now), and if is set, it will use that path to get the location of the modules to load.

vlavella commented 7 years ago

Travis if failing for typings checking with lodash, is solve by adding this dependency: "@types/lodash": "ts2.0", I didn't want to mess up the request with unrelated fixes. I can add it if you want to.

shlomiassaf commented 7 years ago

Hi

Thank you for the contribution!

The AOT compiler resolved genDir relative to the tsconfig file, so I think that's the root cause...

The name of the property should be context since we are setting the context directory for the plugin, this is a common name in webpack to reference a root directory.

The only issue I have is the confusion people will have with genDir, this is a very tricky setup and setting them both together is not trivial if you don't know how the system works...

I will check why travis fails... I don't want to commit the dist files into the repository...

Thanks!

shlomiassaf commented 7 years ago

@vlavellauruit Can you remove the dist commit and upgrade to "@types/lodash": "ts2.0" using yarn (so the lockfile updates)

If you don't have yarn i'll do it...

Thanks, Shlomi.