Mojolicious-Plugin-AssetPack-Che

 view release on metacpan or  search on metacpan

lib/Mojolicious/Plugin/AssetPack/Pipe/VueTemplateCompiler.pm  view on Meta::CPAN


=head1 NAME

Mojolicious::Plugin::AssetPack::Pipe::VueTemplateCompiler - if you like separate files vue template and vue scrtipt.


=head1 SYNOPSIS

  $app->plugin('AssetPack::Che' => {
          pipes => [qw(VueTemplateCompiler CombineFile)],
          VueTemplateCompiler=>{# pipe options
            enabled=>$ENV{MOJO_ASSETPACK_VUE_TEMPLATE_COMPILER} || 0,
            # dist_template pass to Mojo::Template->render, $content is compiled source template to JS render and staticRenderFns
            dist_template=>q|parcelRequire.register("<%= $asset_url %>", (function(){<%= $content %>; return {render,staticRenderFns};})());|,
          },
          process => [
            ['js/dist/templates/app★.js?bla'=>qw(components/foo.vue.html components/bar.vue.html)],
            ['app.js'=>qw('js/dist/templates/app★.js components/foo.vue.js components/bar.vue.js)],
            ...,
          ],
        });


=head1 Конфигурация CONFIG

Обработка файлов-шаблонов B<< \<path|url>.vue.html >> пойдет только (ONLY) в режиме development.

Обработанные топики шаблонов сохраняются в пути этого топика относительно static L<https://metacpan.org/pod/Mojolicious#static>.

В режиме production эти топики используются как обычные ассеты.


=head1 SEE ALSO

L<Mojolicious::Plugin::AssetPack::Che>

L<Mojolicious::Plugin::AssetPack>

=head1 AUTHOR

Михаил Че (Mikhail Che), C<< <mche[-at-]cpan.org> >>

=head1 BUGS / CONTRIBUTING

Please report any bugs or feature requests at L<https://github.com/mche/Mojolicious-Plugin-AssetPack-Che/issues>. Pull requests also welcome.

=head1 COPYRIGHT

Copyright 2020-2021 Mikhail Che.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

__DATA__
@@ vue-template-compiler.js
#!/usr/bin/env node
"use strict"

let fs = require("fs");
let stdinBuffer = fs.readFileSync(0); // STDIN_FILENO = 0

const compiler = require('vue-template-compiler');
const util = require('@vue/component-compiler-utils');

///et c = compiler.compile(stdinBuffer.toString());

///let errs = c.errors;

//if (errs && errs.length) 
///  console.error(errs);


///delete c.ast;
///delete c.errors;

//console.log(c);
//process.stdout.write(JSON.stringify(c));
///process.stdout.write(c.render);

/***
  https://github.com/vuejs/component-compiler-utils#api
***/

let parse = util.parse({
  source: stdinBuffer.toString(),
  //~ filename?: string
  compiler,
  needMap: false,
});


let template = util.compileTemplate({
  source: parse.template.content,
  //~ filename: 
  compiler,
  isProduction: true,
  //~ transformAssetUrls: false,////susama
  //~ prettify:false,
  //~ isFunctional:true,
  //~ compilerOptions: {
    //~ scopeId
  //~ },
});

if (Array.isArray(template.errors) && template.errors.length >= 1) {
  //~ throw new Error(template.errors[0]);
  console.error(template.errors);
}
      
process.stdout.write(template.code);



( run in 2.461 seconds using v1.01-cache-2.11-cpan-d8267643d1d )