ChuHoMan / vue-demi-component-template

SFC template of vue-demi project, can dev & test & build 编写基于 vue-demi 单文件组件模板库
MIT License
35 stars 11 forks source link

Documentation is not clear #13

Closed nimatrengo closed 1 year ago

nimatrengo commented 1 year ago

First of all, I really like the innovation and the approach, I cloned the boilerplate to implement Vue3 components and use them in Vue2.7, I was not able to import the Vue2.7 generated component in my Vue2.7 host application as the package.json is exporting the vue3 that is not rendering on Vue2.7. So I had to change the export manually in the package.json to make it happen, and then it works, I could not see any guidance in the documentation, Maybe it was not clear to me. Also it was not mentioning that we have to use install function to register the component. This is my fix:

"exports": {
        ".": {
            "types": "./dist/v3/index.d.ts",
            "import": "./dist/v3/index.es.js",
            "require": "./dist/v3/index.cjs.js"
        },
        "./vue2": {
            "types": "./dist/v2.7/index.d.ts",
            "import": "./dist/v2.7/index.es.js",
            "require": "./dist/v2.7/index.cjs.js"
        }
    },

and in Vue2 application

import {TemplateComponent} from "vue-demi-template-component/vue2"
TemplateComponent.install(Vue);
ChuHoMan commented 1 year ago

I'm sorry I just saw your comment now. The exports field in the package.json is automatically detected and updated through the postinstall script, so all you need to do is run pnpm install to correctly determine the Vue version currently in use.