chrisvfritz / hello-vue-components

An example component library built with Vue CLI 3.
MIT License
315 stars 42 forks source link

Script inside SFC results in 'component is not defined' error for UMD. #16

Open cbeninati opened 5 years ago

cbeninati commented 5 years ago

Steps to reproduce

  1. Pull hello-vue-components from GitHub
  2. Runnpm install
  3. Update src/HelloA.vue (see changes below)
  4. Run npm run build
  5. View the output ./dist/demo.html in the browser (Chrome)
  6. Errors like the Dickens!!! (single error, screenshot below)
Screen Shot 2019-04-12 at 11 22 54 AM

Change to the SFC

...
<!-- HelloA.vue -->

<script>
  export default {
    name: 'hello-a',
    data() {
      return {
        name: 'HelloA',
      }
    },
  }
</script>
...

Complete SFC

<!-- HelloA.vue -->

<template>
  <div class="hello">
   {{ name }}
  </div>
</template>

<script>
  export default {
    name: 'hello-a',
    data() {
      return {
        name: 'HelloA',
      }
    },
  }
</script>

<style>
.hello {
  color: orange;
}
</style>

<meta>
{
  "description": "A component that says \"HelloA\" with orange text."
}
</meta>

<example>
  <!-- No props or content are necessary. -->
  <hello-a></hello-a>
</example>
midejesus commented 5 years ago

I think there is a problem with the file global-vue-loader.js I'm not expert in node, but looks like it's trying to replace the export default with this window.Vue.component('${componentName}', component.exports) and component.exports is not defined. I'm having the same problem. Any guess on what to replace here?

tiagosimoesdev commented 4 years ago

Any solution for adding script to components ?