我編譯故我在:誰說 Node.js 程式不能編成 binary

81
我編譯故我在 Node.js 程式不能編成 Binary Fred Chien

Transcript of 我編譯故我在:誰說 Node.js 程式不能編成 binary

Page 1: 我編譯故我在:誰說 Node.js 程式不能編成 binary

我編譯故我在

誰說 Node.js 程式不能編成 Binary

Fred Chien

Page 2: 我編譯故我在:誰說 Node.js 程式不能編成 binary

錢逢祥

Fred Chien

Page 3: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Mandice

Page 4: 我編譯故我在:誰說 Node.js 程式不能編成 binary

cfsghost At gmail.com

Page 5: 我編譯故我在:誰說 Node.js 程式不能編成 binary

fred-zone.blogspot.com

Page 6: 我編譯故我在:誰說 Node.js 程式不能編成 binary

StemWonderful JavaScript OS

stem.mandice.org

Page 7: 我編譯故我在:誰說 Node.js 程式不能編成 binary

"You do Everything." customer said.

客戶一向說我是萬能的

Page 8: 我編譯故我在:誰說 Node.js 程式不能編成 binary

But

Page 9: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Hard to get paid for Everything

從他們口袋裡多拿錢

卻萬萬不能

Page 10: 我編譯故我在:誰說 Node.js 程式不能編成 binary

One day

某天

Page 11: 我編譯故我在:誰說 Node.js 程式不能編成 binary

More requests are coming

客戶又要追加一堆免錢功能

Page 12: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Fucx

很 X

Page 13: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Do It

於是我決定

Page 14: 我編譯故我在:誰說 Node.js 程式不能編成 binary

At night

做完那天晚上

Page 15: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Be Strong

硬起來

Page 16: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Only 72 hours for getting paid

給自己 72 小時通諜的勇氣

Page 17: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Damn It !

但是

Page 18: 我編譯故我在:誰說 Node.js 程式不能編成 binary

The Next Day

第二天

Page 19: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Customer goes abroad

客戶就出國去了

Page 20: 我編譯故我在:誰說 Node.js 程式不能編成 binary

And Ignore me

直接忽略了我的請款

Page 21: 我編譯故我在:誰說 Node.js 程式不能編成 binary

oops

!@#$%^&*

Page 22: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Assert ourself

悍衛主權啦!

Page 23: 我編譯故我在:誰說 Node.js 程式不能編成 binary

So

於是

Page 24: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Do some hacks

我把軍艦開到他家

Page 25: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Hide everything

把程式碼都藏起來

Page 26: 我編譯故我在:誰說 Node.js 程式不能編成 binary

The Next Morning

第二天早上

Page 27: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Customers surrendered themself

客戶立馬從國外

打電話回來說要付錢

Page 28: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Customers surrendered themself

還派他的特使小姐

來收我的發票

Page 29: 我編譯故我在:誰說 Node.js 程式不能編成 binary
Page 30: 我編譯故我在:誰說 Node.js 程式不能編成 binary

in 72 hours

72 小時的成果

Page 31: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Node.js Packaging Utility

NPK

Page 32: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Node.js 程式碼封裝工具

NPK

Page 33: 我編譯故我在:誰說 Node.js 程式不能編成 binary

https://github.com/cfsghost/npk

npk at Github

Page 34: 我編譯故我在:誰說 Node.js 程式不能編成 binary

npm install npk -g

Install via NPM

Page 35: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Obfuscation

面目全非

Page 36: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Compress and Minify

壓縮

Page 37: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Bundle all in single file

封裝成單一檔案

Page 38: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Compile it to binary file

編譯成二進位檔

Page 39: 我編譯故我在:誰說 Node.js 程式不能編成 binary

The point is

最酷的是

Page 40: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Supported 3 levels

NPK 支援三種封裝等級

Page 41: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Remove mock-up

卸了妝 認不得

Page 42: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Your Mom doesn't recognize

媽媽不認得

Page 43: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Your Dad doesn't recognize as well

爸爸也不認得

Page 44: 我編譯故我在:誰說 Node.js 程式不能編成 binary

So

所以

Page 45: 我編譯故我在:誰說 Node.js 程式不能編成 binary

It make sense

這樣的設計應該很合理

Page 46: 我編譯故我在:誰說 Node.js 程式不能編成 binary

$ npk . --remove-mockup

$ npk . --mom-doesnt-recognize

$ npk . --dad-doesnt-recognize

Page 47: 我編譯故我在:誰說 Node.js 程式不能編成 binary
Page 48: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Trying to explain these levels

簡單來說

Page 49: 我編譯故我在:誰說 Node.js 程式不能編成 binary

縮排脫掉,變數脫掉,空白脫掉,通通脫掉

卸了妝

Page 50: 我編譯故我在:誰說 Node.js 程式不能編成 binary

加密壓縮程式碼

媽都不認得

Page 51: 我編譯故我在:誰說 Node.js 程式不能編成 binary

用 Compiler 編譯成 Binary

爸也不認得

Page 52: 我編譯故我在:誰說 Node.js 程式不能編成 binary
Page 53: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Workflow

js filejs file

js file

js file

Generate Symbol Table and Object files

Link all to generate final package file

Page 54: 我編譯故我在:誰說 Node.js 程式不能編成 binary
Page 55: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Package your Node.js code

打包你的 Node.js 程式

Page 56: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Modify package.json for NPK

修改 package.json

Page 57: 我編譯故我在:誰說 Node.js 程式不能編成 binary

{"name": "example-project","desciption": "Example program","version": "0.0.1","npk_target": {

"app.js": {"sources": [

"app.js","lib/a.js","lib/b.js"

]}

}}

Modifying package.json

Page 58: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Pack Now!

開始打包!

Page 59: 我編譯故我在:誰說 Node.js 程式不能編成 binary

npk /home/fred/myproject

npk [project path]

可以配合服用爸媽不認得參數

Page 60: 我編譯故我在:誰說 Node.js 程式不能編成 binary

你將會得到

out/app.js/app.js

Page 61: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Where is the thing dad doesn't recognize?

爸不認得的Code在哪?

Page 62: 我編譯故我在:誰說 Node.js 程式不能編成 binary

out/app.js/build/Release/npk.node

Page 63: 我編譯故我在:誰說 Node.js 程式不能編成 binary

:-)

Live Demo

Page 64: 我編譯故我在:誰說 Node.js 程式不能編成 binary
Page 65: 我編譯故我在:誰說 Node.js 程式不能編成 binary

You might ask what ...

你可能最想問的是

Page 66: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Is it reliable to protect our code?

NPK 真的靠的住嗎?

Page 67: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Absolutely No

靠不住

Page 68: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Gentleman should not steal code

防君子

Page 69: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Customer should pay for code

防客戶

Page 70: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Somebody is evil

但是最怕

Page 71: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Source code is still there

失傳的還我漂漂拳

Page 72: 我編譯故我在:誰說 Node.js 程式不能編成 binary

What's Next?

Page 73: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Encryption, LLVM... etc

Page 74: 我編譯故我在:誰說 Node.js 程式不能編成 binary

歡迎命名投搞

也許有下一個封裝等級?

Page 75: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Welcome to punch my face

打臉時間

Page 76: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Advertisement

最後宣傳一下

Page 77: 我編譯故我在:誰說 Node.js 程式不能編成 binary

StemWonderful JavaScript OS

stem.mandice.org

Page 78: 我編譯故我在:誰說 Node.js 程式不能編成 binary

需要 JS 開發者的幫忙!Wanted You

Page 79: 我編譯故我在:誰說 Node.js 程式不能編成 binary

JavaScript 硬起來!

Page 80: 我編譯故我在:誰說 Node.js 程式不能編成 binary

歡迎跟我聯繫或交換名片 :-)

cfsghost At gmail.com

Page 81: 我編譯故我在:誰說 Node.js 程式不能編成 binary

Thanks