How to use the parseComponent function from vue-template-compiler
Find comprehensive JavaScript vue-template-compiler.parseComponent code examples handpicked from public code repositorys.
vue-template-compiler.parseComponent is a function that parses a single-file Vue component and returns its script, template and style blocks as separate objects.
204 205 206 207 208 209 210 211 212 213
} const args = [destinationFolder, sourceFolder]; if (template.script) { const newJs = parseJSDependencies(template.script.content, ...args); sourceContents = insertContent(sourceContents, template.script, newJs); template = vueTemplateCompiler.parseComponent(sourceContents); } template.styles.forEach(style => { const newStyle = parseScssDependencies(style.content, ...args); sourceContents = insertContent(sourceContents, style, newStyle);
492
589
41
+ 59 other calls in file
GitHub: leechipang/grpc007
30 31 32 33 34 35 36 37 38 39 40 41 42
} module.exports = function (src, filePath, jestConfig) { const vueJestConfig = getVueJestConfig(jestConfig) var parts = vueCompiler.parseComponent(src, { pad: true }) if (parts.script && parts.script.src) { parts.script.content = fs.readFileSync(join(filePath, '..', parts.script.src), 'utf8') }
0
0
1
+ 16 other calls in file
How does vue-template-compiler.parseComponent work?
vue-template-compiler.parseComponent
is a method provided by the Vue.js template compiler that allows you to extract the script, template, and style sections of a Vue.js single-file component (SFC) and parse them into their respective ASTs (abstract syntax trees). It can be used to generate an object that contains the extracted sections, as well as other metadata such as the filename and the source map.
Ai Example
1 2 3 4 5 6 7 8 9
const { parseComponent } = require("vue-template-compiler"); const fs = require("fs"); const sfc = fs.readFileSync("MyComponent.vue", "utf8"); const parsed = parseComponent(sfc); console.log(parsed.script.content); // prints the script content console.log(parsed.template.content); // prints the template content console.log(parsed.styles[0].content); // prints the first style content
vue-template-compiler.parseComponent is the most popular function in vue-template-compiler (77 examples)