程式碼打包工具

程式碼打包工具

相似於 Webpack , Deno 提供了簡易的程式碼打包工具:

> deno bundle https://deno.land/std@0.73.0/examples/colors.ts colors.bundle.js
Bundle https://deno.land/std@0.73.0/examples/colors.ts
Download https://deno.land/std@0.73.0/examples/colors.ts
Download https://deno.land/std@0.73.0/fmt/colors.ts
Emit "colors.bundle.js" (9.83KB)

輸入 deno bundle [URL] colors.bundle.js 以後,我們就可以得到 colors.bundle.js

如果沒有聽過 Webpack 也沒關係,讀者可以參考今天的延伸閱讀。

出於好奇心,筆者也將之後會用到的範例程式拿出來打包看看:

原始檔 1 :

let a = function(i: number,j: number): number{
	return 3.5*i+(-6.6*j)
	}
function b(i: number,j: number) :number{
	return 6.6+(8.8*i)-3.5*j
	}
function MatrixC(i :number,j :number){
	let result = 0;
	for (var x = 1;x <= 60; x++) {
		let c = a(i,x)*b(x,j)
		result = result + c;
	}
	return result
}
export { a,b,MatrixC }

原始檔 2 :

打包後:

執行結果: 正常!

需要注意的是,匯出程式碼的附檔名必須為 .js ,若是 .ts 會無法順利執行。

為什麼筆者知道呢?

因為: 我踩過的坑,我知道。

Last updated

Was this helpful?