Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vue-cli build a lib from component and import it

I'm using vue-cli for build my lib with this command:

"build": "vue-cli-service build --target lib --name myLib ./src/component.vue"

How can I import my component from the dist folder after the build?

If I import from path-to-myLib/src/component.vue, everything is fine! But the code below does not work:

// undefined
import { component } from 'path-to-myLib/dist/myLib.umd.js' 
// undefined
import myComponent'path-to-myLib/dist/myLib.umd.js' 
// result: https://i.sstatic.net/xHSzL.png
import * as myComponent'path-to-myLib/dist/myLib.umd.js'

I cannot understand what the problem is.

like image 365
Илья Зеленько Avatar asked Dec 01 '25 02:12

Илья Зеленько


1 Answers

you must add main to your package.json like this "main":"path-to-myLib/dist/myLib.umd.js", pointing to the generated umd file and then use import {component} from 'library' and use in library library name

like image 51
giorgiosaud Avatar answered Dec 02 '25 15:12

giorgiosaud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!