How to use the @vue/component-compiler-utils.compileTemplate function in @vue/component-compiler-utils

To help you get started, we’ve selected a few @vue/component-compiler-utils 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 ElemeFE / element / build / md-loader / util.js View on Github external
function genInlineComponentText(template, script) {
  // https://github.com/vuejs/vue-loader/blob/423b8341ab368c2117931e909e2da9af74503635/lib/loaders/templateLoader.js#L46
  const finalOptions = {
    source: `<div>${template}</div>`,
    filename: 'inline-component', // TODO:这里有待调整
    compiler
  };
  const compiled = compileTemplate(finalOptions);
  // tips
  if (compiled.tips &amp;&amp; compiled.tips.length) {
    compiled.tips.forEach(tip =&gt; {
      console.warn(tip);
    });
  }
  // errors
  if (compiled.errors &amp;&amp; compiled.errors.length) {
    console.error(
      `\n  Error compiling template:\n${pad(compiled.source)}\n` +
        compiled.errors.map(e =&gt; `  - ${e}`).join('\n') +
        '\n'
    );
  }
  let demoComponentContent = `
    ${compiled.code}
github vuejs / vue-loader / lib / loaders / templateLoader.js View on Github external
// for vue-component-compiler
  const finalOptions = {
    source,
    filename: this.resourcePath,
    compiler,
    compilerOptions,
    // allow customizing behavior of vue-template-es2015-compiler
    transpileOptions: options.transpileOptions,
    transformAssetUrls: options.transformAssetUrls || true,
    isProduction,
    isFunctional,
    optimizeSSR: isServer && options.optimizeSSR !== false,
    prettify: options.prettify
  }

  const compiled = compileTemplate(finalOptions)

  // tips
  if (compiled.tips && compiled.tips.length) {
    compiled.tips.forEach(tip => {
      loaderContext.emitWarning(typeof tip === 'object' ? tip.msg : tip)
    })
  }

  // errors
  if (compiled.errors && compiled.errors.length) {
    // 2.6 compiler outputs errors as objects with range
    if (compiler.generateCodeFrame && finalOptions.compilerOptions.outputSourceRange) {
      // TODO account for line offset in case template isn't placed at top
      // of the file
      loaderContext.emitError(
        `\n\n  Errors compiling template:\n\n` +
github dcloudio / uni-app / packages / vue-cli-plugin-hbuilderx / packages / webpack-uni-nvue-loader / lib / templateLoader.js View on Github external
// for vue-component-compiler
  const finalOptions = {
    source,
    filename: this.resourcePath,
    compiler,
    compilerOptions,
    // allow customizing behavior of vue-template-es2015-compiler
    transpileOptions: options.transpileOptions,
    transformAssetUrls: options.transformAssetUrls || true,
    isProduction,
    isFunctional,
    optimizeSSR: isServer && options.optimizeSSR !== false,
    prettify: options.prettify
  }

  const compiled = compileTemplate(finalOptions)

  // tips
  if (compiled.tips && compiled.tips.length) {
    compiled.tips.forEach(tip => {
      loaderContext.emitWarning(typeof tip === 'object' ? tip.msg : tip)
    })
  }

  // errors
  if (compiled.errors && compiled.errors.length) {
    // 2.6 compiler outputs errors as objects with range
    if (compiler.generateCodeFrame && finalOptions.compilerOptions.outputSourceRange) {
      // TODO account for line offset in case template isn't placed at top
      // of the file
      loaderContext.emitError(
        `\n\n  Errors compiling template:\n\n` +
github kaola-fed / megalo-aot / packages / target / lib / frameworks / vue / loader / template.js View on Github external
const finalOptions = {
        source,
        filename: this.resourcePath,
        compiler,
        compilerOptions: Object.assign( {}, compilerOptions, {
          imports: cOptions.imports,
        } ),
        // allow customizing behavior of vue-template-es2015-compiler
        transpileOptions: options.transpileOptions,
        transformAssetUrls: options.transformAssetUrls || true,
        isProduction,
        isFunctional,
        optimizeSSR: false
      }

      const compiled = compileTemplate(finalOptions)

      // tips
      if (compiled.tips && compiled.tips.length) {
        compiled.tips.forEach(tip => {
          loaderContext.emitWarning(tip)
        })
      }

      // errors
      if (compiled.errors && compiled.errors.length) {
        loaderContext.emitError(
          `\n  Error compiling template:\n${pad(compiled.source)}\n` +
            compiled.errors.map(e => `  - ${e}`).join('\n') +
            '\n'
        )
      }
github youzan / vant / packages / vant-cli / src / compiler / compile-sfc.ts View on Github external
function compileTemplate(template: string) {
  const result = compileUtils.compileTemplate({
    compiler,
    source: template,
    isProduction: true
  } as any);

  return result.code;
}
github vuejs / vue-jest / lib / process.js View on Github external
function processTemplate(template, filename, config) {
  if (!template) {
    return null
  }

  const vueJestConfig = getVueJestConfig(config)

  if (template.src) {
    template.content = loadSrc(template.src, filename)
  }

  const result = compilerUtils.compileTemplate({
    source: template.content,
    compiler: VueTemplateCompiler,
    filename: filename,
    compilerOptions: {
      optimize: false
    },
    isFunctional: template.attrs.functional,
    preprocessLang: template.lang,
    preprocessOptions: vueJestConfig[template.lang]
  })

  logResultErrors(result)

  return result
}
github jackmellis / require-extension-hooks-vue / src / index.js View on Github external
) {
  if (!template) {
    return '';
  }

  const content = retrieveAndTranspileContent(
    filename,
    template,
    hook,
    [ 'html' ],
    globalConfig.transpileTemplates && transpileTemplateSpecial
  );

  const isFunctional = template.attrs.functional;

  const compiled = compileTemplate({
    source: content,
    filename,
    compiler,
    compilerOptions: { preserveWhitespace: false },
    isFunctional
  });

  return [
    compiled.code,
    `;${COMPONENT_OPTIONS}.render=render;`,
    `${COMPONENT_OPTIONS}.staticRenderFns=staticRenderFns;`,
    `${COMPONENT_OPTIONS}._compiled = true;`,
    isFunctional ? `${COMPONENT_OPTIONS}.functional = true;` : ''
  ].join('\n');
}
github ktsn / vue-template-loader / lib / modules / template-compiler.js View on Github external
module.exports = function compile (template, options = {}) {
  const compiled = compileTemplate({
    source: template,
    filename: options.filename,
    compiler,
    transformAssetUrls: options.transformAssetUrls,
    isFunctional: options.functional,
    isProduction: options.isProduction,
    optimizeSSR: options.optimizeSSR
  })

  if (compiled.errors.length > 0) {
    return {
      errors: compiled.errors,
      code: empty
    }
  }

@vue/component-compiler-utils

Lower level utilities for compiling Vue single file components

MIT
Latest version published 3 years ago

Package Health Score

69 / 100
Full package analysis