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.1k
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
640
Oxlint JS plugins
kazupon
1
1.3k
gunshi
kazupon
1
230
Nitro v3
kazupon
2
550
わたしのOSS活動
kazupon
3
620
Vapor Revolution
kazupon
3
4.2k
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
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
220
技術記事、 専門家としてのプログラマ、 言語化
mizchi
12
5k
Oxcを導入して開発体験が向上した話
yug1224
4
310
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
780
Claspは野良GASの夢をみるか
takter00
0
190
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
3.7k
TAKTでAI駆動開発の品質を設計する
j5ik2o
6
1.2k
A2UI という光を覗いてみる
satohjohn
1
130
AIだと陥りがちなJakarta EE最新技術への移行時の落とし穴と解決策
tnagao7
0
100
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
5.5k
ふつうのFeature Flag実践入門
irof
7
3.7k
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
110
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
55
10k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
390
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
200
Claude Code のすすめ
schroneko
67
230k
sira's awesome portfolio website redesign presentation
elsirapls
0
280
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
840
Between Models and Reality
mayunak
4
330
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
230
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
200
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
200
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
350
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
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!