Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 937dea1

Browse files
author
Andy
authored
Merge pull request #331 from Microsoft/move_wildcards
Move discussion of wildcard modules to Modules.md
2 parents b5843d7 + c2d901d commit 937dea1

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

pages/Module Resolution.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,6 @@ A non-relative import can be resolved relative to `baseUrl`, or through path map
4242
They can also resolve to [ambient module declarations](./Modules.md#ambient-modules).
4343
Use non-relative paths when importing any of your external dependnecies.
4444

45-
## Wildcard module declarations
46-
47-
Some module loaders such as [SystemJS](https://github.com/systemjs/systemjs/blob/master/docs/overview.md#plugin-syntax)
48-
and [AMD](https://github.com/amdjs/amdjs-api/blob/master/LoaderPlugins.md) allow non-JavaScript content to be imported.
49-
These typically use a prefix or suffix to indicate the special loading semantics.
50-
Wildcard module declarations can be used to cover these cases.
51-
52-
```ts
53-
declare module "*!text" {
54-
const content: string;
55-
export default content;
56-
}
57-
// Some do it the other way around.
58-
declare module "json!*" {
59-
const value: any;
60-
export default value;
61-
}
62-
```
63-
64-
Now you can import things that match `"*!text"` or `"json!*"`.
65-
66-
```ts
67-
import fileContent from "./xyz.txt!text";
68-
import data from "json!http://example.com/data.json";
69-
console.log(data, fileContent);
70-
```
71-
7245
## Module Resolution Strategies
7346

7447
There are two possible module resolution strategies: [Node](#node) and [Classic](#classic).

pages/Modules.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,33 @@ import x, {y} from "hot-new-module";
517517
x(y);
518518
```
519519

520+
### Wildcard module declarations
521+
522+
Some module loaders such as [SystemJS](https://github.com/systemjs/systemjs/blob/master/docs/overview.md#plugin-syntax)
523+
and [AMD](https://github.com/amdjs/amdjs-api/blob/master/LoaderPlugins.md) allow non-JavaScript content to be imported.
524+
These typically use a prefix or suffix to indicate the special loading semantics.
525+
Wildcard module declarations can be used to cover these cases.
526+
527+
```ts
528+
declare module "*!text" {
529+
const content: string;
530+
export default content;
531+
}
532+
// Some do it the other way around.
533+
declare module "json!*" {
534+
const value: any;
535+
export default value;
536+
}
537+
```
538+
539+
Now you can import things that match `"*!text"` or `"json!*"`.
540+
541+
```ts
542+
import fileContent from "./xyz.txt!text";
543+
import data from "json!http://example.com/data.json";
544+
console.log(data, fileContent);
545+
```
546+
520547
### UMD modules
521548

522549
Some libraries are designed to be used in many module loaders, or with no module loading (global variables).

0 commit comments

Comments
 (0)