Morgul / snowpack-plugin-vue2

A snowpack vue2 compiler that reuses `@snowpack/plugin-vue` verbatim.
MIT License
6 stars 2 forks source link

Extending SFC components does not work. #1

Closed Morgul closed 3 years ago

Morgul commented 3 years ago

Attempting to follow the Vue Typescript Guide leads to declaring a sample component like this:

<template>
    <div id="main-app">
      Message: {{ msg }}
    </div>
</template>

<style lang="scss">
    #main-app {
        height: calc(100% - 64px);
    }
</style>

<script lang="ts">
    import Vue from 'vue';
    export default Vue.extend({
        data()
        {
            return {
                msg: 'Hello, Vue!'
            }
        }
    });
</script>

However, compiling this with snowpack-plugin-vue2 yields the following error message:

image

mszekiel commented 3 years ago

I have this error and it would be really helpful to be working :(

Morgul commented 3 years ago

I haven't had a chance to start digging into the output to understand why one works, and the other doesn't. My plan is to keep working on in it in the upcoming week.

Morgul commented 3 years ago

Just an update (more for myself as a reminder when I get back to this). I've spent some time this afternoon digging into this, and comparing the Vue3 compiler output to the Vue2 one, they both output the script section identically:

import Vue from "vue";
const defaultExport = Vue.extend({
  name: "SimpleVue",
  data() {
    return {
      msg: "Hello!"
    };
  }
});

Whatever the bug is, it's actually at the Vue level; something about how Vue.extends works in Vue2 vs Vue3. As a side note, I have not confirmed this works in Vue 3; that would be something to try as well; maybe this is just broken with how Snowpack's building the module to wrap an SFC?

Morgul commented 3 years ago

Good news! looks like vue-loader has the solution, I think:

https://github.com/vuejs/vue-loader/blob/master/lib/runtime/componentNormalizer.js#L17-L20

I've gotta figure out the most minimal way to shove this into the plugin, but I think it should fix this issue.

As a workaround, @mszekiel, you should be able to just stick .options on the end, i.e.:

export default Vue.extend({
  name: "SimpleVue",
  data() {
    return {
      msg: "Hello!"
    };
  }
}).options;

That seemed to work in the brief test I just did. I'll work on a new version of the plugin with a proper fix shortly.

Morgul commented 3 years ago

This is fixed in v0.2.0, which was just published.