//index.html
<script type="module">
import ์๋ช
from './main.js'
// ๊ฐ์ ธ์จ ๊ฒ์ ์๋ช
์ ํ ๋น/ ๊ฒฝ๋ก
</script>
//main.js
var a = 10;
export default a;
๐งจ export default๋ ํ์ผ๋น 1ํ๋ง ์ฌ์ฉ ๊ฐ๋ฅ
var a = 10;
var b = 20;
export { a, b };
---------
export var a = 10;
์ด๋ ๊ฒ๋ ๊ฐ๋ฅ
๐งจ ์ฌ๋ฌ ๋ณ์ import ์์๋ ์ ํํ ๋ณ์ ๋ช ์ ์ ๋ ฅํด์ผ ํ๋ค.
//index.html
import {a, b} from './main.js'
console.log(a)
a ๋ง ๊ฐ์ ธ์ค๊ณ ์ถ์ผ๋ฉด {a}.
๊ฐ๋ฅ
var a = 10;
var b = 20;
var c = 30;
export { a, b };
export default c;
//index.html
import ์๋ช
, {a, b} from './main.js'
๐งจ default import๋ ๋งจ ์์ ์์น.
import {a as ์๋ช
} from './main.js'
import * as ๋ณ๋ช
from './main.js'
console.log(๋ณ๋ช
.a)
๐งจ default๋ ๋ฐ๋ก ๊ฐ์ ธ์์ผํจ.
import ๋ํดํธ, * as ๋ณ๋ช
from './main.js'
(export ํ๋ jsํ์ผ)
module.exports.a = 10 ;
------------------------
(import ํ๋ jsํ์ผ)
var ๊ฐ์ ธ์จ๊ฒ๋ค = require('/library.js');