How to use the vue-template-compiler/build.parseComponent function in vue-template-compiler

To help you get started, we’ve selected a few vue-template-compiler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shuidi-fed / vuese / packages / parser / lib / sfcToAST.ts View on Github external
export function sfcToAST(
  source: string,
  babelParserPlugins?: BabelParserPlugins,
  basedir?: string
): AstResult {
  const plugins = getBabelParserPlugins(babelParserPlugins)
  const sfc = parseComponent(source)
  const res: AstResult = {}
  if (sfc.script) {
    if (!sfc.script.content && sfc.script.src) {
      // Src Imports
      if (basedir) {
        try {
          sfc.script.content = fs.readFileSync(
            path.resolve(basedir, sfc.script.src),
            'utf-8'
          )
        } catch (e) {
          console.error(e)
          sfc.script.content = ''
        }
      }
    }
github max-team / Mars / packages / mars-build / src / compiler / sfc / parser.js View on Github external
exports.parse = function parse(file, options, withWrap = true) {
    const {target} = options;

    const content = preParse(file.contents.toString());
    let {
        script = {},
        template = {},
        styles = [{}],
        customBlocks = []
    } = parseComponent(content, {});

    let configBlocks = {
        default: [],
        target: []
    };
    customBlocks.forEach(block => {
        if (block.type === 'config') {
            if (!block.attrs.target) {
                configBlocks.default.push(block);
            }

            if (block.attrs.target === (process.env.MARS_ENV_TARGET || target)) {
                configBlocks.target.push(block);
            }
        }