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.2k
Oxlint JS plugins
kazupon
1
1.4k
gunshi
kazupon
1
240
Nitro v3
kazupon
2
570
わたしのOSS活動
kazupon
3
630
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
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
370
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
220
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
220
プロポーザルを書いてもらう
pvcresin
0
280
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
370
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
160
yield再入門 #phpcon
o0h
PRO
0
970
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
180
React本体のコードリーディング
high_g_engineer
1
140
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
290
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
180
Featured
See All Featured
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.5k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.3k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
The Limits of Empathy - UXLibs8
cassininazir
1
590
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Marketing to machines
jonoalderson
1
5.6k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
430
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
370
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
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!