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.7k
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
590
自己的售票系統自己做!
eddie
0
610
AI Agent 時代的開發者生存指南
eddie
4
2.7k
print("Hello, World")
eddie
2
650
為你自己學 Python - 冷知識篇
eddie
1
460
為你自己學 Python
eddie
0
760
Generative AI 年會小聚 - AI 教我寫程式
eddie
0
220
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
760
AI 時代的程式語言學習法
eddie
0
260
Other Decks in Programming
See All in Programming
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.9k
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
150
tsserverとは何だったのか、これからどうなるのか
nowaki28
1
460
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
150
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
210
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
180
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1.2k
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
200
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
560
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
250
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
180
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.3k
Featured
See All Featured
Building Adaptive Systems
keathley
44
3k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.3k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Agile that works and the tools we love
rasmusluckow
331
21k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
What's in a price? How to price your products and services
michaelherold
247
13k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
860
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
Test your architecture with Archunit
thirion
1
2.3k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
380
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