Skip to content

feature(import resolving): ability to import (ts, sass etc.) with path alias #2392

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

Conversation

ValeryVS
Copy link
Contributor

Closes #1465 #2254

Example imports

before

import { SharedModule } from '../../../../../shared';
@import '../../../../../styles/variables'

after

import { SharedModule } from '@app/shared';
@import '~@app/styles/variables'

Why not just use tsconfig.json?

1.
Because tsconfig.'s paths and webpack's alias syntax is different.
You can use

"@app/*": [
  "app/*"
]

for child directories or

"@app": [
  "app"
]

for app directory itself in tsconfig, but you need

alias: {
  "@app": "/path_to_project/src/app"
}

in webpack's resolve configuration.

2.
Because these aliases also affect sass imports.

@ValeryVS ValeryVS force-pushed the feature/inner-module-resolver-add-to-cli-config branch 2 times, most recently from 040ca4c to d3455e1 Compare September 28, 2016 14:08
@ValeryVS ValeryVS force-pushed the feature/inner-module-resolver-add-to-cli-config branch from d3455e1 to 94962e7 Compare September 28, 2016 15:16
@ghost
Copy link

ghost commented Sep 28, 2016

Another PR solving this issue :) Hope this one will be approved and merged! Good stuff.

@clydin
Copy link
Member

clydin commented Sep 29, 2016

This works but is fairly fragile. The tsconfig.json needs to be aligned with angular-cli.json and the user can only use a restricted set of the rich path mapping support found in typescript. It also directly exposes a webpack setting.

As an alternate solution (for typescript), the new loader could be extended to fully support typescript's paths option by using typescript's module resolution and rewriting relevant imports. This is actually a more complete solution then ATL's plugin; as it would allow the loader to mimic the behavior of tsc (in terms of module resolution) and not pollute webpack's global module resolution. The sass-loader uses a similar concept to apply the sass import semantics.

As to stylesheets, exposure of the underlying preprocessor include path settings could be a solution.

@filipesilva
Copy link
Contributor

Superseded by #2470.

@filipesilva filipesilva closed this Oct 2, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add project source dir as a module
4 participants