Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
模組化前端開發:從亂七八糟到組織有序
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
710
自己的售票系統自己做!
eddie
0
760
AI Agent 時代的開發者生存指南
eddie
4
2.9k
print("Hello, World")
eddie
2
740
為你自己學 Python - 冷知識篇
eddie
1
550
為你自己學 Python
eddie
0
860
Generative AI 年會小聚 - AI 教我寫程式
eddie
0
310
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
830
AI 時代的程式語言學習法
eddie
0
350
Other Decks in Programming
See All in Programming
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
120
Python Lambdaにおけるテストしやすい設計とAI支援の活用 / Designing Testable Python Lambda Functions with AI
kitano_yuichi
1
200
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
120
dotNET_vulnclicker_intro.pdf
deka_morita
0
150
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
6
1.9k
Vue Fes Japan の “作る側”に関わってみて
naokihaba
1
190
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
810
JIS keyboard support in Omarchy
lef237
0
160
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
4
960
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
380
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
420
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.4k
Featured
See All Featured
Fireside Chat
paigeccino
43
4.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
Believing is Seeing
oripsolob
1
250
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
710
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
620
Automating Front-end Workflow
addyosmani
1370
210k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
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