FranckFreiburger / vue3-sfc-loader

Single File Component loader for Vue2 and Vue3. Load .vue files directly from your HTML. No node.js environment, no build step.
MIT License
1.2k stars 127 forks source link

feat(core): add vue2 support #25

Closed Toilal closed 3 years ago

Toilal commented 3 years ago

I try to include vue2 support to this module. This is currently a draft because it seems to compile properly but I still need to do some tests.

FranckFreiburger commented 3 years ago

Interesting ! Just keep in mind that my first concern is the final bundle size.

Toilal commented 3 years ago

Yes, I just saw the dist file is huge now in this branch, but there's probably some tweeks to perform in webpack configuration. Maybe it should build another file for vue2 (with another webpack entrypoint).

FranckFreiburger commented 3 years ago

Hi,

FYI, vue3-sfc-loader src has been refactored. src/createSFCModule.ts is now the "interface" for vue2/vue3 :

export async function createSFCModule(source : string, filename : string, options : Options, loadModule : LoadModule) : Promise<ModuleExport>

See also webpack config :

alias: {
    './createSFCModule.ts': `./createVue${ vueVersion }SFCModule.ts`,
    ...
Toilal commented 3 years ago

Thanks.

The webpack alias is an option, but it seems to me there's mostly common behaviors to share between the createVue2SFCModule.ts and createVue3SFCModule.ts, so this will lead to some duplicated code (even if you have extracted some common functions in tools.js, there's still many features that needs to be duplicated like componentHash/scopeId, language processor preloading, global workflow, ...).

I currently have to build an app where end-user can build new forms through a back office UI. My idea is to build a WYSIWYG editor supporting some vuetify components through live compiling of SFC files, but vuetify still doesn't support vue3 (it's just been released in alpha though), so I currently need vue2 support.

I also have some side project ideas using this "live compiling Vue SFC stuff", so I still hesitate into contributing to your repository or creating my own set of libraries. In such a case, it would be a monorepo with many published packages (compiler-core, compiler-vue2, compiler-vue3, babel-vue3, ...). I wish to have a node version too, using node internal modules instead of browserify ones. But anyway for now i'll try to rebase the vue2 version with your changes.

Toilal commented 3 years ago

Ok, I have rework the vue2 integration with your changes. It seems OK to me, the first "Hello World" test is OK in basic.vue2.test.js and i'll try to port all vue3 tests in the next few days.

FranckFreiburger commented 3 years ago

looks really promising (happy to be able to archive http-vue-loader soon). About createVue2SFCModule.ts and createVue3SFCModule.ts factorization, I agree that we can do more, maybe a bit later ?

btw, thanks for your contribution !

PS:

Toilal commented 3 years ago

Thanks for merging this pull request. Of course, it can be refactored later. For now, i'll try to make scoped style work properly and copy/paste tests from vue3 version.

I wish to release a WYSIWYG view editor publicly, but it won't happen shortly.