Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

es-module

add.js

// ch01-before-webpack/02-history-of-js-module/es-module/add.js
export default function (a, b) {
  return a + b;
}

使用 export default 導出預設模組。

index.js

// ch01-before-webpack/02-history-of-js-module/es-module/index.js
import add from './add.js';

console.log(add(1, 2)); // 3

使用 import 導入模組。

index.html

<!-- ch01-before-webpack/02-history-of-js-module/es-module/index.html -->
<!DOCTYPE html>
<html>
  <head>
    <script src="index.js" type="module"></script>
    <script src="add.js" type="module"></script>
  </head>
  <body></body>
</html>

使用 type 設定為 module<script> 引用 index.jsadd.js