forked from denoland/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update
deno_std
and import map docs (denoland#459)
- Loading branch information
Showing
1 changed file
with
22 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,20 +38,30 @@ written something similar in our `deno.json` configuration file: | |
} | ||
``` | ||
|
||
## Example - Using deno_std's fmt module via `fmt/` | ||
## Example - Using the Deno Standard Library | ||
|
||
Running the following: | ||
|
||
```bash | ||
deno add @std/foo | ||
``` | ||
|
||
Produces the following: | ||
|
||
```json title="deno.json" | ||
{ | ||
"imports": { | ||
"fmt/": "https://deno.land/std@$STD_VERSION/fmt/" | ||
"@std/foo": "jsr:@std/foo@^1.2.3" | ||
} | ||
} | ||
``` | ||
|
||
```ts title="color.ts" | ||
import { red } from "fmt/colors.ts"; | ||
The import can then be used in your script: | ||
|
||
```ts title="bar.ts" | ||
import { bar } from "@std/foo"; | ||
|
||
console.log(red("hello world")); | ||
bar(1, 2); | ||
``` | ||
|
||
## Example - Using project root for absolute imports | ||
|
@@ -79,19 +89,20 @@ import map's URL or file path. | |
The other situation where import maps can be very useful is to override imports | ||
in specific modules. | ||
|
||
Let's say you want to override the deno_std import from 0.177.0 to the latest in | ||
all of your imported modules, but for the `https://deno.land/x/example/` module | ||
you want to use files in a local `patched` directory. You can do this by using a | ||
scope in the import map that looks something like this: | ||
Let's say you want to override a Deno Standard Library package import from | ||
^1.2.3 to the latest in all of your imported modules, but for the | ||
`https://deno.land/x/example/` module you want to use files in a local `patched` | ||
directory. You can do this by using a scope in the import map that looks | ||
something like this: | ||
|
||
```json | ||
{ | ||
"imports": { | ||
"https://deno.land/[email protected]/": "https://deno.land/std@$STD_VERSION/" | ||
"@std/foo": "jsr:@std/foo@^1.2.3" | ||
}, | ||
"scopes": { | ||
"https://deno.land/x/example/": { | ||
"https://deno.land/[email protected]/": "./patched/" | ||
"@std/foo": "./patched/mod.ts" | ||
} | ||
} | ||
} | ||
|