Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
模組化前端開發:從亂七八糟到組織有序
Search
高見龍
November 08, 2023
Programming
1.8k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
模組化前端開發:從亂七八糟到組織有序
高見龍
November 08, 2023
More Decks by 高見龍
See All by 高見龍
宅宅自以為的浪漫:跟 AI 一起為自己辦的研討會寫一個售票系統
eddie
0
620
自己的售票系統自己做!
eddie
0
630
AI Agent 時代的開發者生存指南
eddie
4
2.8k
print("Hello, World")
eddie
2
660
為你自己學 Python - 冷知識篇
eddie
1
470
為你自己學 Python
eddie
0
780
Generative AI 年會小聚 - AI 教我寫程式
eddie
0
230
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
780
AI 時代的程式語言學習法
eddie
0
280
Other Decks in Programming
See All in Programming
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
540
関数型プログラミングのメリットって何だろう?
wanko_it
0
190
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
230
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
850
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
190
霧の中の代数的エフェクト
funnyycat
1
420
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.6k
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.7k
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
540
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
150
php-fpmのプロセスが枯渇した日-調査・対処・そして本当にやるべきだったこと-
shibuchaaaan
0
130
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
130
Featured
See All Featured
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
340
Ethics towards AI in product and experience design
skipperchong
2
330
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
Site-Speed That Sticks
csswizardry
13
1.3k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Color Theory Basics | Prateek | Gurzu
gurzu
0
400
Thoughts on Productivity
jonyablonski
76
5.3k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.9k
Visualization
eitanlees
152
17k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
230
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
420
Transcript
五倍學院 從亂七八糟到組織有序
五倍學院 愛玩、愛現,喜歡冷門的玩具 網站開發者、講師、作家 技術推廣、企業訓練、技術諮詢 部落格:kaochenlong.com 高見龍 @eddiekao
五倍學院
五倍學院 從亂七八糟到組織有序
五倍學院
五倍學院 前端?不就是寫網頁的嘛
五倍學院 模組化?
五倍學院 JavaScript = 玩具 1995 年
五倍學院 你知道在最初版本的 JS 是沒有陣列的嗎?
五倍學院 石器時代
五倍學院 模組化?
五倍學院 no module
五倍學院 <script type="text/javascript"> $().ready(function () { console.log("MWC 2023"); }); </
script> $
五倍學院 <script src="jquery.min.js"> < / script> <script type="text/javascript"> $().ready(function ()
{ console.log("MWC 2023"); }); </ script>
五倍學院 載入的順序很重要
五倍學院 <script type="text/javascript"> $().ready(function () { console.log("MWC 2023"); }); </
script> <script src="jquery.min.js"> < / script>
五倍學院 套件放在 <head> 裡, 自己寫的放 </body> 前
五倍學院 污染全域變數
五倍學院 使用 IIFE Immediately Invoked Function Expression
五倍學院 const MyApp = MyApp || {} MyApp.UserModule = (function
() { // 登入功能 function login(username, password) {} // 登出功能 function logout() {} return { login, logout } })() MyApp.UserModule.login("mwc", "2023") MyApp.UserModule.logout() 模組化!
五倍學院 官方不做,社群做!
五倍學院 戰國時代
五倍學院 群魔亂舞 / 群雄割據 CommonJS, AMD/CMD, UMD...etc
五倍學院 CommonJS
五倍學院 // 我是 mwc_mod.js const MWC = function () {
console.log("ModernWeb Conference") } module.exports.MWC = MWC
五倍學院 // 我是 main.js const mod = require("./mwc_mod.js") console.log(mod) //
{ MWC: [Function: MWC] } mod.MWC() // 印出 ModernWeb Conference
五倍學院 // 我是 mwc_mod.js const MWC = function () {
console.log("ModernWeb Conference") } module.exports.MWC = MWC 這是什麼?
五倍學院 console.log(module) // { // id: '.', // path: '/private/tmp/mwc-demo',
// exports: { MWC: [Function: MWC] }, // filename: '/private/tmp/mwc-demo/m.js', // loaded: false, // children: [], // paths: [ // '/private/tmp/mwc-demo/node_modules', // '/private/tmp/node_modules', // '/private/node_modules', // '/node_modules' // ] // } 在這裡!
五倍學院 console.log(module.exports === exports) // true
五倍學院 const MWC = function () { console.log("ModernWeb Conference") }
// module.exports.MWC = MWC exports.MWC = MWC 同樣效果
五倍學院 // 我是 mwc_mod.js const MWC = function () {
console.log("ModernWeb Conference") } exports.MWC = MWC exports = "謝謝你 9527" console.log(exports) // 印出 謝謝你 9527 console.log(module.exports) // { MWC: [Function: MWC] } 咦?
五倍學院 同步載入
五倍學院 AMD Asynchronous Module Definition
五倍學院 非同步
五倍學院 require.js
五倍學院 // 我是 hello.js define(function () { const hello =
function () { console.log("HELLO") } return { hello, } }) // 我是 world.js define(function () { const world = function () { console.log("WORLD") } return { world, } }) 模組 模組
五倍學院 <!DOCTYPE html> <html> <head> <script src="require.js" data-main="main"> </ script>
<title>MWC 2023 </ title> </ head> <body> </ body> </ html> 發動!
五倍學院 // 我是 main.js require(["hello", "world"], function (h, w) {
h.hello() w.world() }) 載入
五倍學院 UMD Universal Module Definition
五倍學院 (function (root, factory) { if (typeof define === "function"
&& define.amd) { // 是 AMD! define(["deps"], factory) } else if (typeof exports === "object") { // 是 CommonJS! module.exports = factory(require("deps")) } else { // 其它,來去全域變數上塞東 西 ! root.MyModule = factory(root) } })(this, function (deps) { return { MWC: function () { console.log("ModernWeb Conference") }, year: "2023", } }) 檢查 檢查 IIFE
五倍學院 jQuery
五倍學院 https: // 5xcamp.us/jquery-source
五倍學院 ESM? ES Module 2015 年
五倍學院 工業革命時代
五倍學院 Node = 蒸汽機
五倍學院 轉譯、打包、建置工具!
五倍學院 https: // webpack.js.org/
五倍學院 支援多種模組系統 CommonJS, AMD, ESM...etc
五倍學院 webpack.config.js 🤮
五倍學院 https: // parceljs.org/
五倍學院 esbuild
五倍學院 天下武功,唯快不破
五倍學院 https: // esbuild.github.io/
五倍學院 為什麼這麼快?
五倍學院 Go
五倍學院 https: // bun.sh/
五倍學院 Zig
五倍學院 大內捲時代
五倍學院 https: // rollupjs.org/
五倍學院 Tree-Shaking 除屑優化
五倍學院 // 我是 extra_fish.js const 工 具 人 = "🛠🔨🔧⛏"
function 多餘() { console.log("不是多了塊 魚 🐟,是多餘,你呀,你根本就是多餘呀你") } function MWC(year) { return `ModernWeb Conference ${year}` } console.log(MWC(2023)) :)
五倍學院
五倍學院 現代
五倍學院 瀏覽器原生支援 ESM! import vue from 'react' 🙌
五倍學院 https: // developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Statements/import
五倍學院 <script type="module"> </ script>
五倍學院 <!DOCTYPE html> <html> <head> <title>MWC 2023 </ title> <script
type="module"> import has from "lodash-es/has.js" </ script> </ head> <body> </ body> </ html>
五倍學院
五倍學院 <!DOCTYPE html> <html> <head> <title>MWC 2023 </ title> <script
type="module"> import has from "./node_modules/lodash-es/has.js" </ script> </ head> <body> </ body> </ html> 👌
五倍學院 <!DOCTYPE html> <html> <head> <title>MWC 2023 < / title>
<script type="module"> import day from "./node_modules/dayjs/dayjs.min.js" </ script> < / head> <body> </ body> </ html>
五倍學院
五倍學院 Vite /vit/
五倍學院 Vite 不是 Vue 的專武!
五倍學院 Vite 不是打包工具
五倍學院 esbuild ↢ Vite ↣ Rollup pre- bundling production bundle
dev server
五倍學院 HMR
五倍學院 https: // 5xcamp.us/mwc-vite
五倍學院 https: // twitter.com/youyuxi/status/1709943106215530867
五倍學院 Rollup ↣ Rolldown
五倍學院 Rust
五倍學院 https: // 5xcamp.us/ithome-rust
五倍學院 importmap
五倍學院 <script type="module"> </ script>
五倍學院 <script type="importmap"> </ script>
五倍學院 <!DOCTYPE html> <html> <head> <title>MWC 2023 </ title> <script
type="importmap"> { "imports": { "dayjs": "https: // ga.jspm.io/npm:
[email protected]
/dayjs.min.js" } } < / script> </ head> <body> < / body> < / html>
五倍學院 這不就 CDN 嗎?
五倍學院 <!DOCTYPE html> <html> <head> <title>MWC 2023 </ title> <script
type="importmap"> { "imports": { "dayjs": "https: / / ga.jspm.io/npm:
[email protected]
/dayjs.min.js", "mwc-day": "https: // ga.jspm.io/npm:
[email protected]
/dayjs.min.js" } } </ script> <script type="module"> import day from "dayjs" import d from "mwc-day" </ script> < / head> <body> < / body> < / html>
五倍學院 no bundle
五倍學院 這樣效能好嗎?CDN 穩定嗎?
五倍學院 https: // 5xcamp.us/
五倍學院 擺脫 node_modules! 🙌
五倍學院 更多關於 importmap
五倍學院 12/16
五倍學院 工商服務 實體、線上課程、企業內訓 有時間 來實體 沒時間 買線上
五倍學院 工商服務 Node / Python / Django / Rust 課程
有時間 來實體 沒時間 買線上
五倍學院 愛玩、愛現,喜歡冷門的玩具 網站開發者、講師、作家 技術推廣、企業訓練、技術諮詢 部落格:kaochenlong.com 高見龍 @eddiekao