[Vuejs]-Import vue.js plugin is undefined

1👍

Webpack is assuming that you have exported a default property.

You can do that like so:

export default {
  install: function(Vue,config) {
    //do something
  }
}

If you don’t want to use default, you’ll need to export it using a named variable:

export const MyPlugin = {
  install: function(Vue,config) {
    //do something
  }
}

And then specifically reference that variable reference that when importing:

import { MyPlugin } from 'my-plugin'

Here’s a working example.

1👍

I finally use another script as webpack entry.

entry.js:

module.exports=require('./main')

main.js:

function install(Vue,config){
  //something
}
export default {install}

then it can be access in window.myplugin and import myplugin from 'myplugin'

Leave a comment