src/vuegister.js
function load(buf, file, cfg) {
  if (typeof buf !== 'string') {
    throw new TypeError('First argument must be a string.');
  }

  cfg = Object.assign({
    maps: false,
    lang: {script: 'js', template: 'html'},
    plugins: {},
  }, cfg);

  let vue = {};

  for (let section of extract(buf, ['script', 'template'])) {
    let attrs = section.attrs;
    let lang = has(attrs, 'lang') ? attrs.lang : cfg.lang[section.tag];

    if (has(attrs, 'src')) {
      let dir = file ? path.dirname(file) : process.cwd();

      file = path.resolve(dir, attrs.src);
      section.text = fs.readFileSync(file, 'utf8');
    }

    let transpiled = transpile(lang, section.text, {
      file,
      maps: cfg.maps,
      offset: section.offset,
      extra: Object.assign({}, cfg.plugins[lang]),
    });

    vue[section.tag] = transpiled.data;

    if (cfg.maps && transpiled.map) {
      sourceMapsCache.set(file, transpiled.map);
    }
  }

  vue.script += injectTemplate(vue.template);

  return vue.script;
}
function load(buf, file, cfg) {
  if (typeof buf !== 'string') {
    throw new TypeError('First argument must be a string.');
  }

  cfg = Object.assign({
    maps: false,
    lang: {script: 'js', template: 'html'},
    plugins: {},
  }, cfg);

  let vue = {};

  for (let section of extract(buf, ['script', 'template'])) {
    let attrs = section.attrs;
    let lang = has(attrs, 'lang') ? attrs.lang : cfg.lang[section.tag];

    if (has(attrs, 'src')) {
      let dir = file ? path.dirname(file) : process.cwd();

      file = path.resolve(dir, attrs.src);
      section.text = fs.readFileSync(file, 'utf8');
    }

    let transpiled = transpile(lang, section.text, {
      file,
      maps: cfg.maps,
      offset: section.offset,
      extra: Object.assign({}, cfg.plugins[lang]),
    });

    vue[section.tag] = transpiled.data;

    if (cfg.maps && transpiled.map) {
      sourceMapsCache.set(file, transpiled.map);
    }
  }

  vue.script += injectTemplate(vue.template);

  return vue.script;
}
function load ( buf , file , cfg ) { if ( typeof buf !== 'string' ) { throw new TypeError ( 'First argument must be a string.' ) ; } cfg = Object . assign ( { maps : false , lang : { script : 'js' , template : 'html' } , plugins : { } , } , cfg ) ; let vue = { } ; for ( let section of extract ( buf , [ 'script' , 'template' ] ) ) { let attrs = section . attrs ; let lang = has ( attrs , 'lang' ) ? attrs . lang : cfg . lang [ section . tag ] ; if ( has ( attrs , 'src' ) ) { let dir = file ? path . dirname ( file ) : process . cwd ( ) ; file = path . resolve ( dir , attrs . src ) ; section . text = fs . readFileSync ( file , 'utf8' ) ; } let transpiled = transpile ( lang , section . text , { file , maps : cfg . maps , offset : section . offset , extra : Object . assign ( { } , cfg . plugins [ lang ] ) , } ) ; vue [ section . tag ] = transpiled . data ; if ( cfg . maps && transpiled . map ) { sourceMapsCache . set ( file , transpiled . map ) ; } } vue . script += injectTemplate ( vue . template ) ; return vue . script ; }
Parses SFC, high level API.

@alias module:vuegister
@param {string} buf - Content of the SFC file.
@param {string} [file] - Full path to the SFC.
@param {object} [cfg] - Options, an object of the following format:
```js
{
maps: boolean,   // false, provide source map
lang: object,    // {}, default language for tag without lang attribute,
// for example:
// {
//   {script: 'js'}
// }
plugins: object, // {}, user configuration for the plugins, for example:
// {
//   babel: {
//     babelrc: true,
//   },
// }
}
```
@return {string} Returns ready-to-use JavaScript with injected template.
Parses SFC high level API .