1

I'm using webpack with vuejs and I'm trying to put as much stuff as I can in vendor.js so that my app.js can be smaller so that webpack build time can be reduced.

I'm trying to register Font Awesome vuejs version globally.

in my main.js

import Icon from 'vue-awesome';
window.Icon = Icon;
Vue.use(Icon);

And in my component .vue file I have

<template>
    <icon name="beer"></icon>
</template>

<script>
    export default {

    components: {
        Icon: window.Icon
    }

}
</script>

And I am getting this error: Unknown custom element: <icon> - did you register the component correctly?

window.Icon is set correctly I can log it, but i think i am doing some rookie mistake here, because when i include it locally in the component directly everything is working.

5
  • Try lower-case "i" for your component name: icon: window.Icon Commented Apr 7, 2017 at 20:06
  • @RoyJ didn't work :( Commented Apr 7, 2017 at 20:08
  • Just looking at vue-awesome docs, shouldn't you import Icon in way like this import Icon from 'vue-awesome/components/Icon.vue' ? Commented Apr 7, 2017 at 20:29
  • 1
    You need to do Vue.use() within each module. github.com/vuejs-templates/webpack/issues/63 Commented Apr 7, 2017 at 20:31
  • @RoyJ thanks If you post it as an answer i will accept it. Commented Apr 7, 2017 at 20:41

1 Answer 1

2

in a module environment such as CommonJS, you always need to call Vue.use() explicitly

A longer discussion is here: https://github.com/vuejs-templates/webpack/issues/63, but the gist is that each module must call Vue.use().

Sign up to request clarification or add additional context in comments.

2 Comments

So it's synonymous with import, include and require constructs from other languages?
@JaredFarrish no, there are still native js import and require. Vue.use installs a plugin in order to extend Vue functionality.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.