-
Notifications
You must be signed in to change notification settings - Fork 129
[ko] Fix typo - Module Resolution #78
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
skyuecx0630
commented
Jun 7, 2021
- Removed unnecessary html tags.
Translation of Module Resolution.mdtitle: Module Resolution translatable: true
Module analysis is a process used by the compiler to find out what import refers to. At this point, the compiler is " First, the compiler will try to find the location of the file that represents the imported module. If this method is not good and the module name is non-relative , ( Finally, if the compiler is not able to interpret the module, an error log occurs. Relative vs. Non-Relative Module importsDepending on the module reference relative or non-relative, the module import is interpreted differently. Relative import is
All other imports Non-relative is considered .
Relative import is interpreted relative to imported files and interpreted as ambient module declarations can't be. Non-relative import Module Analysis StrategiesThere are two possible module analysis strategies: nodeand classic. Classic (Classic)Used as the default analysis strategy for TypeScript. The relative import is interpreted relative to the file you import.
However, in a non-relative module import, the compiler starts with the directory that has the imported file and goes back to the directory tree to find the location of the appropriate definition file. For example: Source file
Node (Node)This analysis strategy Node.jsattempts to mimic the module analysis mechanism in . How .js interprets modules (How Node.js resolves modules)To understand what the TS compiler will follow, it is .js node and other modules. The relative path is very simple.
For more information, see node.js article File Moduleand Folder moduleYou can read more at . however Non-relative module nameThe interpretation of performs differently. Follow the example above,
Note .js jumped directories in (4) and (7). For more information about the process, see the Node.js article How TypeScript interprets modules (How TypeScript resolves modules)TypeScript mimics Node's runtime analysis strategy to find the location of the module.js at compile-time. For example
Node.js Similarly, the non-relative import follows .js node, follows the analysis logic, firstly finds the file, and then finds the corresponding folder.
Don't be afraid because you can step-typeScript and still jump twice from the directory (9) and 17. It'.js more complicated than Node" does. Additional module analysis flagsIn some areas, the project source layout does not match the output. The TypeScript compiler has additional flags. The compiler also does not perform these conversions. Does note that it is; Default URL (Base URL)
_baseUrl_The value of is determined by one of the following:
Note that the relative module import is always relatively interpreted by the imported file, so it is not affected by setting baseUrl. More articles on baseUrl RequireJSand SystemJS You can find it in the article. Path mappingSometimes a module baseUrl It may not be located below. The TypeScript compiler {
"compilerOptions": {
"baseUrl": ".", // "paths"가 있는 경우 반드시 지정되어야함.
"paths": {
"jquery": ["node_modules/jquery/dist/jquery"] // 이 매핑은 "baseUrl"에 상대적임.
}
}
}
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": [
"*",
"generated/*"
]
}
}
} This gives the compiler a pattern in two locations.
By following this logic, the compiler will try to interpret two imports: import 'folder1/file2':
import 'folder2/file3':
|
LGTM |
Merging because @yeonjuan is a code-owner of all the changes - thanks! |