You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This module is a runtime utility for cleaner component module output and will
be included in the final webpack user bundle.
normalizeComponent 对 style 的处理:
第一步,生成一个样式加载的函数
/* 样式加载函数 */varhookif(moduleIdentifier){// server buildhook=function(context){// 2.3 injectioncontext=context||// cached call(this.$vnode&&this.$vnode.ssrContext)||// stateful(this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)// functional// 2.2 with runInNewContext: trueif(!context&&typeof__VUE_SSR_CONTEXT__!=='undefined'){context=__VUE_SSR_CONTEXT__}// inject component stylesif(injectStyles){injectStyles.call(this,context)}// register component module identifier for async chunk inferrenceif(context&&context._registeredComponents){context._registeredComponents.add(moduleIdentifier)}}// used by ssr in case component is cached and beforeCreate// never gets calledoptions._ssrRegister=hook}elseif(injectStyles){hook=shadowMode
? function(){injectStyles.call(this,this.$root.$options.shadowRoot)}
: injectStyles}
第二步,样式加载函数作为钩子函数执行
if(hook){console.log('\n\n options: ',options)if(options.functional){// for template-only hot-reload because in that case the render fn doesn't// go through the normalizeroptions._injectStyles=hook// register for functioal component in vue filevaroriginalRender=options.renderoptions.render=functionrenderWithStyleInjection(h,context){hook.call(context)returnoriginalRender(h,context)}}else{// inject component registration as beforeCreate hookvarexisting=options.beforeCreateoptions.beforeCreate=existing
? [].concat(existing,hook)
: [hook]}}
生成 loaderString
生成一个 require 的 string,用来加载style
// todo
selector,
selector 是 loaderString 中的第一个 loader,用来选择 .vue 文件的对应代码块
// todo
style-compiler
style-compiler
// todo
vue-style-loader
vue-style-loader 生成动态插入样式的代码
// todo
The text was updated successfully, but these errors were encountered:
vue-loader v14 中对 style 的载入是一个动态的载入
一个 .vue 文件经过 vue-loader 后,style 会是一个注入函数
injectStyle 是经过
selector
,style-compiler
,css-loader
,vue-style-loader
后生成的一个注入函数,随后被作为参数传入了normalizeComponent()
normalizeComponent
而关于
normalizeComponent
, 文件里的注释如下,说的是这个函数是属于 runtime 的,打包后才运行的normalizeComponent
对 style 的处理:生成
loaderString
生成一个
require
的string
,用来加载style// todo
selector
,selector
是loaderString
中的第一个 loader,用来选择.vue
文件的对应代码块// todo
style-compiler
style-compiler
// todo
vue-style-loader
vue-style-loader
生成动态插入样式的代码// todo
The text was updated successfully, but these errors were encountered: