Closed corysimmons closed 7 years ago
It seems you have a misunderstanding about how JSX is used - it's used in the javascript, like this:
<script>
export default {
name: 'app',
data() {
return {
msg: 'Welcome to Your Vue.js App'
};
},
render (h) {
return (
<div id="app">
{this.msg}
</div>)
}
};
</script>
<style scoped>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
}
</style>
So there's no <template>
anymore...
Okay, can there be?
Can <template lang="jsx">
just be a wrapper like:
render (h) {
return (
________________________)
}
<template lang="jsx">
<div id="app">
{this.msg}
</div>
</template>
...with transform plugins already bundled?
That's cool. I wonder if it could simply be return required('./Foo.jsx)
in there though? 🤔
fwiw, I like Vue for it's single-page component stuff (simplifies all that build stuff), but prefer jsx (like a lot of other people I talk to).
That's cool. I wonder if it could simply be
return required('./Foo.jsx)
in there though? 🤔
Unfortunately, no. vue-loader first runs the <script>
through Babel (or any other transpiler you might have specified, like typescript), then converts what is in <template>
to a JS and adds that generated code as the render function to the transpiled JS.
So Babel is already done once vue-loader takes care of <template>
, which means we would have to make vue-loader work its tasks in a different order for this special case etc. pp.
fwiw, I like Vue for it's single-page component stuff (simplifies all that build stuff), but prefer jsx (like a lot of other people I talk to).
Well as I demonstrated above, you can sue JSX in an SFC - just not in <template>
I appreciate you chatting with me about this.
you can sue JSX in an SFC - just not in
Yeah but then you end up with huge SFC (all template and all scripts).
It's okay, I'll figure something out in the future. Thanks for your patience. 🙇
I used the vue-cli to create a simple browserify project, then added this plugin. JSX still isn't working in single-file components. Not sure what I'm doing wrong.