The entrance

Platforms /platforms/web/ entry-run-time withcompiler there is this logic when executing $mount in SRC /platforms/web/ entry-run-time withcompiler

About compilation of entry is here, compileToFunctions method is to compile the template template to generate and render staticRenderFns, its definition in the SRC/platforms/web/compiler/index. Js

compileToFunctions

The compileToFunctions method is actually the return value of the createCompiler method, which takes a compile configuration parameter, baseOptions

createCompiler

The createCompiler method is actually returned by calling the createCompilerCreator method, which takes a function as an argument, and the real compilation is done in this baseCompile function.

createCompilerCreator

This method returns a createCompiler function that takes a baseOptions argument and returns an object containing compile method properties and compileToFunctions, The compileToFunctions corresponding is $mount compileToFunctions method of function calls, it is call createCompileToFunctionFn methods return values.

createCompileToFunctionFn

At this point we’ve finally found the final definition of compileToFunctions, which takes three parameters, compiles the template, compiles the configuration options and the Vue instance VM. Compiled = compile(template, options) Const compiled = compile(template, options)

compile

The compile function at the time of execution createCompileToFunctionFn passed as a parameter, it is createCompiler function defined in the compile function, compile function performs the logic is to first processing configuration parameters, Const compiled = baseCompile(template.trim(), finalOptions)

baseCompile

BaseCompile is passed in as a parameter when the createCompilerCreator method is executed, so we finally find the compile entry, which basically implements the above three logic.

conclusion

The compiler entry logic is so convoluting because vue. js will be compiled on different platforms, so the baseOptions depend on during compilation will be different. The compilation process will be executed several times, but the configuration of each compilation process on the same platform is the same. In order to prevent these configurations from being passed in through parameters in each compilation process, vue. js uses the function Currization technique to achieve the parameter reservation of baseOptions well. Similarly, vue. js also uses the function currization technique to extract the basic compilation process function, and uses createCompilerCreator(baseCompile) to put the real compilation process and other logic such as compilation configuration processing.