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
Vue.js Extend with Compiler
Search
kazupon
September 15, 2017
Programming
4.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Vue.js Extend with Compiler
kazupon
September 15, 2017
More Decks by kazupon
See All by kazupon
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
1.5k
Oxlint JS plugins
kazupon
1
1.4k
gunshi
kazupon
1
250
Nitro v3
kazupon
2
590
わたしのOSS活動
kazupon
3
640
Vapor Revolution
kazupon
3
4.3k
Vue.js最新動向
kazupon
3
1.6k
Vue 3.4
kazupon
13
4.9k
Vue & Vite Rustify
kazupon
4
2.5k
Other Decks in Programming
See All in Programming
My Marp Sample
sinoue0108
0
140
Go 1.27 における memory allocation の高速化
andpad
0
360
PyO3 で既存 Python 評価器を Rust core 化する ー wasm-bindgen でブラウザにも配るための設計
kdash
1
100
How I Won Prize Money at a Hackathon Using Codex and Symphony Alpha
yasei_no_otoko
0
130
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
270
高専、大学編入、そして未踏へ〜プロダクト開発とキャリアの歩み - Technical College, University Transfer, and On to “Mitou” / My Journey in Product Development and Career
pkmiya
0
120
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
300
初めての模倣学習とVLA
natsutan
0
390
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
4
2.4k
まだ間に合う!今年の夏こそSchemeのマクロ展開器を完全理解!
omasanori
0
600
MySQLとPostgreSQLって何が違うの?
akagami
0
150
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
420
Featured
See All Featured
Six Lessons from altMBA
skipperchong
29
4.5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Scaling GitHub
holman
464
140k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
320
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
440
Balancing Empowerment & Direction
lara
6
1.3k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
Building the Perfect Custom Keyboard
takai
2
860
So, you think you're a good person
axbom
PRO
2
2.1k
Transcript
Vue.js Extend with Compiler ToKyotoJS 2017-09-15 @kazupon
Who are you ?
kazupon Vue.js Core Team Vue.js japan users group organizer vue-i18n,
vue docs maintainer storybook vue support member CUUSOO SYSTEM CTO @kazu_pon kazupon
[PR]
2017-10-04
Vue.js v-meetup #5 https://vuejs-meetup.connpass.com/event/65442/
Nuxt.js at Genba Specials! 1.0 coming soon !? Nuxt.js!! Nuxt.js!!
We are hiring!! Let’s building Open Innovation Platform!! http://www.cuusoo.co.jp
Introduction
Vue 2.x Rendering Engine Virtual DOM
• Declarative • Template Flexible Rendering Intuitive, Designer friendly !!
• Imperative • render function + hyperscript Flexible Rendering Programmatic,
Powerful !!
• (Declarative + Imperative ) / 2 ? • JSX
Flexible Rendering
However, Sometimes, we would like to …
• e.g. Pre-Translation of i18n Extend with compiler! I’d like
to Improve Performance !!
Today: Speaking
How to extend with compiler
Overall flow
Overall flow Compilation Phase Rendering Phase
Hookable Compilation Phase AST Optimized AST About detail of Compilation
Phase, See the bellow https://speakerdeck.com/kazupon/vue-dot-js-2-dot-0-server-side-rendering#23 Tokyo Node Festival 2016 : “Vue.js 2.0 αʔόαΠυϨϯμϦϯά” ({JS}) ({JS}) ({JS}) compile optimize generate Hooks Hooks Optimize Keys HTML Parser Optimizer Code Generator
How to compile with yourself
• Vue.compile • vue-template-compiler Provide API or package
• Full build only, Core built-in https://unpkg.com/vue • Generate render,
staticRenderFns function Vue.compile
• Full build only, Core built-in https://unpkg.com/vue • Generate render,
staticRenderFns function Vue.compile Damn…
• Vue Compiler Package https://www.npmjs.com/package/vue-template-compiler • No Vue Runtime, Vue
Compiler only! • Need to install NPM vue-template-compiler npm install -D vue-template-compiler
• Provide some APIs • compiler.compile(template, [options]) • compiler.compileToFunctions(template) •
compiler.ssrCompile(template, [options]) • compiler.ssrCompileToFunction(template) • compiler.parseComponent(file, [options]) vue-template-compiler
• Provide some APIs • compiler.compile(template, [options]) • compiler.compileToFunctions(template) •
compiler.ssrCompile(template, [options]) • compiler.ssrCompileToFunction(template) • compiler.parseComponent(file, [options]) vue-template-compiler Bravo!
Compiler options
• modules • directives • preserveWhitespace We can specify the
following options
• An array of compiler module • compiler module type:
`ModuleOptions` `modules` option
Hooking of compiler module AST Optimized AST compile optimize generate
HTML Parser Optimizer Code Generator compiler module preTransformNode transformNode postTransformNode staticKeys genData transformCode
• An object where have pairs key-value • key: directive
name • value: transform an AST node function `directives` option
Hooking of directive AST Optimized AST compile optimize generate HTML
Parser Optimizer directive1 directiveX directives Code Generator directive2 Call directive hooks before genData hooks
Compilation Examples
• Vue core (for web) https://github.com/vuejs/vue/tree/dev/src/platforms/web/compiler/modules • Weex (for native)
https://github.com/vuejs/vue/tree/dev/src/platforms/weex/compiler/modules • vue-loader (assets <img>,<image> in-line) https://github.com/vuejs/vue-loader/tree/master/lib/template-compiler/ modules • vue-18n-extensions (pre-translation) https://github.com/kazupon/vue-i18n-extensions compiler module
• Vue core (for web) https://github.com/vuejs/vue/tree/dev/src/platforms/web/compiler/directives • Weex (for native)
https://github.com/vuejs/vue/tree/dev/src/platforms/weex/compiler/directives directive
Tips
• Vue official bundler libs(Internal used with it) • vue-loader
: compilerModules • rollup-plugin-vue: compilerOptions Alternative: vue-template-compiler https://vuejs.github.io/rollup-plugin-vue/#/en/2.3/?id=template
Conclusion
Compilation hooks is very powerful! • Vue compiler provide compilation
hooks • It's powerful to extend the library/plugins by Vue compiler
Please well consider • However, In about Apps, don’t abuse
• Your apps breaks down easily in order to depenpent vue compiler • If you’d like to use it, Please well consider
One more thing …
Maybe, Vue compiler evolve?
Thanks!