vue-component-compiler icon indicating copy to clipboard operation
vue-component-compiler copied to clipboard

Integration with transpilers

Open corwin-of-amber opened this issue 4 years ago • 4 comments

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.

corwin-of-amber avatar Mar 25 '21 17:03 corwin-of-amber

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

LinusBorg avatar Mar 25 '21 17:03 LinusBorg

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?

corwin-of-amber avatar Mar 25 '21 17:03 corwin-of-amber

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.

Aaron-Pool avatar Jul 30 '21 15:07 Aaron-Pool

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).

dwightjack avatar Nov 22 '21 01:11 dwightjack