-
Notifications
You must be signed in to change notification settings - Fork 444
Advanced module path mappings #180
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
Comments
If you switch to bleeding edge TypeScript (1.9+), I haven't tested this in 2.0beta, then you can do this via tsconfig.json. Add the following to tsconfig.json:
More info here: TypeStrong/atom-typescript#833 |
It looks like it is available in TypeScript 2.0 beta as well. Here is stackoverflow reference: |
Hey @yvoronen! Yeah, I actually upgraded to 2.0 just for this purpose - it fixes {
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"baseUrl": "./src",
"paths": {
"frameworks": ["client/app/frameworks"],
"components": ["client/app/main/components"],
"pages": ["client/app/main/pages"],
"utility": ["client/app/main/utility"]
}
},
"compileOnSave": false
} ...
map: {
frameworks: 'src/client/app/frameworks/index',
components: 'src/client/app/main/components/index',
pages: 'src/client/app/main/pages/index'
}
... Keep in mind I moved the components directory from the base seed into a "main" directory. So with the above two edits to the configurations, I can do:
If I do: |
it seems you omitted the '*'s. Just below should be sufficient to allow you to import from frameworks/index. You can also get to your components via
My IDE (VSCode) currently does not like these imports, but gulp build.dev works just fine and there are no compile errors. I have another project with same setup, and IDE is totally cool with that. I think you have to set proper path to your local typescript SDK in the IDE, or maybe there is another issue. I haven't had time to compare to the other project where IDE works ok. |
I got IDE to work now. The problem was that there was a second tsconfig.json inside src/client, which the IDE was picking up. That one should look as follows, because it is relative to src/client
And you might need to edit .vscode/settings.json (opens via Preferences->Workspace settings) to add the below
|
@yvoronen Thanks! I'm going to look into this today. |
@NathanWalker @yvoronen I was able to get MOST of the functionality working (tests are screwed up and the desktop app does not load the data.json file) - I mostly just wanted to see the app run in each environment. A few things to get it up and running:
Note:
Some notes...
|
I have the same need as the OP while sketching the structure of a new ng2 app and play around with folders - which means I need to update paths to all model classes and other modules all over the place every time I make a change. @exk0730 your solution above may work but I won't try it as it seems to be overkill and I disagree with the idea of I wonder if maybe For example, after completing the Tour Of Heroes tutorial (took me 4h), I realized that the
With the above file, everything seems to be working fine: IntelliSense available for various Maybe I'm out of track with the OP but I'd really like to get this working. |
@rbosneag I have since moved away from this seed and have started using Webpack. There were numerous problems with building a production build of NativeScript after I enhanced the seed with path mapping, I couldn't figure out how to fix them. I also had some problems with running tests. I would suggest not adding module path mapping if you continue with this seed until someone with more knowledge can actually take a crack at it. As for your "importing a file that imports other modules", I'm not entirely sure what you mean. |
@exk0730 so all your problems are gone with WebPack? I thought As for the file |
@rbosneag I realized I didn't need NativeScript or Electron, so a Webpack starter was a more viable option for me; plus I find Webpack easier to configure, but that's just my personal opinion. I used this starter and it's been working out perfectly so far (I was even able to add path mappings!) You can look at this file and this webpack configuration to see an example of how I set up path mapping. If you need more help, hit me up on gitter so we don't clutter this issue :) |
Current behavior
To import a module:
import { BaseComponent } from '../../frameworks/core/index';
(as seen here)
Expected/desired behavior
To import the same module:
import { BaseComponent } from 'frameworks';
Other information
I've tried a bunch of different things, but either
a) the Typescript compiler doesn't like the import statement (all intellisense becomes broken)
or b) the SystemJS build can't find the module.
If I solve
a, thenboccurs and vice versa - I can't get both of them to work properly. I was wondering if anyone was doing something like this in their own project, or if someone could point me in the right direction to solve this issue.Also, I was wondering what this line did in the seed.config.ts file and if it's at all useful for my issue.
Thanks!
The text was updated successfully, but these errors were encountered: