<script type="importmap">

1
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap

import 에서 사용할 별칭을 지정할 수 있다.
nodejs의 package.json의 exports 와 비슷하네.

사용하는 것에 대해서 

-----------=-----------
import { name as squareName, draw } from "./modules/shapes/square.js";
import { name as circleName } from "https://example.com/shapes/circle.js";
=>
<script type="importmap">
  {
    "imports": {
      "square": "./module/shapes/square.js",
      "circle": "https://example.com/shapes/circle.js" ,
      "shapes/": "./module/shapes/",
      "modules/square": "./module/src/other/shapes/square.js",
       ...
    },
    "scopes": {
      "/modules/custom-shapes/": {
        "square": "https://example.com/modules/shapes/square.js"
      }
    }
  }
</script>

import { name as squareName, draw } from "square";
import { name as circleName } from "circle";
import { name as circleName } from "shapes/circle.js";
import { name as circleName } from "modules/square";
=> 
"square" 를 지정하면 "./module/shapes/square.js" 가 된다.
"circle"를 지정하면 "https://example.com/shapes/circle.js" 가 된다.
"shapes/" 의 경로가 포함되면 "./module/shapes/" 로 대체하여 가져온다. (지정시 끝이 / 로 끝나면 폴더로 본다.)
"modules/square" 처럼 끝이 / 가 없으면 중간에 /가 있어라도 경로가 아니라 파일("./module/src/other/shapes/square.js")을 지칭한다.

import { name as squareName, draw } from "square";  -> imports 에 지정된 "./module/shapes/square.js" 를 가져온다.
import { name as squareName, draw } from "/modules/custom-shapes/square"; -> scopes 에 경로가 포함되어있으므로  "https://example.com/modules/shapes/square.js" 를 가져온다

scopes 를 체크하는 기준
1. scopes 에서 찾음
1.1. 경로 매칭이 긴 것이 우선이 됨.
2. scopes 에서 경로가 없으면 imports 에서 찾음.

scopes 사용 이유는 대충...
같은 모듈이지만 버전 차이 등에 대응

-------------=----------------
이 동작은 js 파일속 import 에도 영향을 미친다.
댓글
  • No Nickname
    No Comment
  • 권한이 없습니다.
    {{m_row.m_nick}}
    -
목록형 📷 갤러리형
제목
[기본형] HTML (with 부트스트랩5.3 , jquery 3.7, vue.js)
유용한 리눅스(LINUX) 명령어
[공지] 기술 게시판
6.29
6.30
7.1
7.2
7.3
7.4
7.5
7.6
7.7
7.8
7.9
7.10
7.11
7.12
7.13
7.14
7.15
7.16
7.17
7.18
7.19
7.20
7.21
7.22
7.23
7.24
7.25
7.26
7.27
7.28
7.29
7.30
7.31
8.1
8.2