vuejs / vue-component-compiler

Compile a single file Vue component into a CommonJS module.
MIT License
344 stars 52 forks source link

Integration with transpilers #113

Open corwin-of-amber opened 3 years ago

corwin-of-amber commented 3 years ago

According to #30, the builder that uses vue-component-compiler is responsible for running the script through whatever transpiler is appropriate (e.g. tsc). Is there a way to know which lang was specified for the <script> tag? For <style>, there is a property preprocessLang on the descriptor, but not for the script.

LinusBorg commented 3 years ago

On the descriptor returned by parse(), you can check descriptor.script.attrs.lang

See vue-loader, for example:

https://github.com/vuejs/vue-loader/blob/66893d70eace99129adf96d9ecd27071e7f6cf38/lib/index.js#L127-L128

corwin-of-amber commented 3 years ago

Nice, thanks! Would it make sense to expose this information through the top-level package component-compiler, since component-compiler-utils is sort of an internal package? E.g., add attrs or lang to CompileResult?

Aaron-Pool commented 3 years ago

Just to add my two cents--I also think @corwin-of-amber's suggestion above would be pretty helpful. Currently, if you want to add additional transpilation to the script block, you can't use the top level component-compiler package, because it doesn't pass that information through to the compiler consumer. I obviously don't expect component-compiler to do any actual work with things like the lang attribute, but to expose that information as metadata to whatever is consuming the compiler results would be helpful.

dwightjack commented 3 years ago

Hello, I have submitted a PR to add the lang property to the CompileResult object. As suggested by @Aaron-Pool, by default, it does nothing, but it might be helpful for other tools (for example, https://github.com/apeschar/esbuild-vue/pull/7).