Skip to content

Instantly share code, notes, and snippets.

@kunyaoxu
Last active September 3, 2019 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunyaoxu/d91af9779e6820f9d0240c9ebfe8474f to your computer and use it in GitHub Desktop.
Save kunyaoxu/d91af9779e6820f9d0240c9ebfe8474f to your computer and use it in GitHub Desktop.
typescript 搭配 requirejs(almond)

本文參考自以下連結

事前準備

  • npm install -g typescript http-server

步驟

  • 把下面三個檔案都載下來放到同一個資料夾
  • 在資料夾開啟終端機
  • 打上 tsc main.ts --module amd --outfile main.js (指令結束後應該會發現多了一個名為 main.js 的檔案)
  • 執行 http-server .
  • 瀏覽器打開 http://127.0.0.1:8080/ 理論上會有畫面,之後打開開發者工具在 console 的地方會看到:
hello world !
i am print
<!DOCTYPE html>
<html>
<head>
<title>hello</title>
</head>
<body>
<div>hello world !</div>
<script src="https://unpkg.com/almond@0.3.3/almond.js"></script>
<script src="/main.js"></script>
<script>
require('main');
</script>
</body>
</html>
import {print} from "./print";
console.log("hello world !");
print();
function print() {
console.log("i am print");
}
export {print};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment