All Projects → FranckFreiburger → Vue3 Sfc Loader

FranckFreiburger / Vue3 Sfc Loader

Licence: mit
Vue3 Single File Component loader for Vue2 and Vue3. Load .vue files directly from your html/js. No node.js environment, no (webpack) build step.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue3 Sfc Loader

Vue2 Web
酷我音乐—vue2、vue-router2、webpack2框架
Stars: ✭ 54 (-43.16%)
Mutual labels:  babel, vue2
Cordova Template Framework7 Vue Webpack
Framework7 - Vue - Webpack Cordova Template with Webpack Dev Server and Hot Module Replacement
Stars: ✭ 630 (+563.16%)
Mutual labels:  babel, vue2
Hare
🐇 Application boilerplate based on Vue.js 2.x, Koa 2.x, Element-UI and Nuxt.js
Stars: ✭ 258 (+171.58%)
Mutual labels:  babel, vue2
Webpack
🔥 A full-featured , A Weex and Vue.js project,which is an awesome solution for building Dingtalk microapp with extremely high performanece.
Stars: ✭ 81 (-14.74%)
Mutual labels:  babel, vue2
Record
Vue + Nodejs + Mongodb构建的校园打卡系统,支持csv文件上传名单🚀
Stars: ✭ 94 (-1.05%)
Mutual labels:  vue2
Code2race
Solve the problem. 😊 If you like ❤ give us a star⭐. HACKTOBERFEST
Stars: ✭ 91 (-4.21%)
Mutual labels:  babel
Gulp Babel
Gulp plugin for Babel
Stars: ✭ 1,305 (+1273.68%)
Mutual labels:  babel
Awesome Coding Javascript
📌 持续构建个人的源码库(JavaScript 原生、常用库、数据结构、算法)
Stars: ✭ 88 (-7.37%)
Mutual labels:  babel
React From Scratch
Building a Modern React App from Scratch in 2021
Stars: ✭ 87 (-8.42%)
Mutual labels:  babel
Eagles
eagles for vue componets of silianpan
Stars: ✭ 95 (+0%)
Mutual labels:  vue2
Webpack Core Usage
webpack2完整系列课程,欢迎阅读。同时欢迎移步我的react全家桶文章全集: https://github.com/liangklfangl/react-article-bucket
Stars: ✭ 94 (-1.05%)
Mutual labels:  babel
Vue Sports
vue全家桶+axios+es6 体育新闻+赛事数据
Stars: ✭ 92 (-3.16%)
Mutual labels:  vue2
Perfectwindows
PerfectWindows 软件家族 - Windows 从未如此完美!
Stars: ✭ 1,326 (+1295.79%)
Mutual labels:  easy-to-use
Babel Plugin React Persist
Automatically useCallback() & useMemo(); memoize inline functions
Stars: ✭ 91 (-4.21%)
Mutual labels:  babel
Simpledialogfragments
A collection of easy to use and extendable DialogFragment's for Android
Stars: ✭ 94 (-1.05%)
Mutual labels:  easy-to-use
Jsx Control Statements
Neater If and For for React JSX
Stars: ✭ 1,305 (+1273.68%)
Mutual labels:  babel
Vue Toastr
Vuejs Toast : Plugin and Component Capability.
Stars: ✭ 93 (-2.11%)
Mutual labels:  vue2
Shortstack
🥞 minimal Rollup + PostCSS modern syntax starter template
Stars: ✭ 94 (-1.05%)
Mutual labels:  babel
One Vue
仿韩寒「ONE · 一个」,基于vue2.0+混合式开发的一款跨终端、高性能、用户体验高的移动端App! 学习Vue的同学可以看下,感谢 Star 和 Fork!!
Stars: ✭ 93 (-2.11%)
Mutual labels:  vue2
Quasar Starter Kit
Quasar CLI Starter Kit
Stars: ✭ 92 (-3.16%)
Mutual labels:  vue2

vue3-sfc-loader

Vue3/Vue2 Single File Component loader.
Load .vue files dynamically at runtime from your html/js. No node.js environment, no (webpack) build step needed.

Key Features

  • Supports Vue 3 (dist/vue3-sfc-loader.js) and Vue 2 (dist/vue2-sfc-loader.js)
  • Only requires Vue runtime-only build
  • Focuses on component compilation. Network, styles injection and cache are up to you (see example below)
  • Embedded ES6 modules support ( including import() )
  • SFC Custom Blocks support
  • JSX support
  • Custom CSS, HTML and Script language Support, see pug and stylus examples
  • Properly reports template, style or script errors through the log callback
  • Easily build your own version and customize browsers you need to support

Example

<html>
<body>
  <div id="app"></div>
  <script src="https://unpkg.com/[email protected]"></script>
  <script src="https://cdn.jsdelivr.net/npm/vue3-sfc-loader/dist/vue3-sfc-loader.js"></script>
  <script>

    const options = {
      moduleCache: {
        vue: Vue
      },
      async getFile(url) {

        const res = await fetch(url);
        if ( !res.ok )
          throw Object.assign(new Error(res.statusText + ' ' + url), { res });
        return await res.text();
      },
      addStyle(textContent) {

        const style = Object.assign(document.createElement('style'), { textContent });
        const ref = document.head.getElementsByTagName('style')[0] || null;
        document.head.insertBefore(style, ref);
      },
    }

    const { loadModule } = window['vue3-sfc-loader'];

    const app = Vue.createApp({
      components: {
        'my-component': Vue.defineAsyncComponent( () => loadModule('./myComponent.vue', options) )
      },
      template: '<my-component></my-component>'
    });

    app.mount('#app');

  </script>
</body>
</html>

More Examples

see all examples

Try It Online

https://codepen.io/franckfreiburger/project/editor/AqPyBr

Public API documentation

loadModule(path: string, options: Options): Promise<VueComponent>

dist/

latest bundle version bundle minified+brotli size bundle minified+gzip size bundle minified size Snyk Vulnerabilities for vue3-sfc-loader

browser support

Vue3 compiler-sfc dependency version Vue2 vue-template-compiler dependency version

latest minified Vue3 version at :

latest minified Vue2 version at :

Build your own version

webpack --config ./build/webpack.config.js --mode=production --env targetsBrowsers="> 1%, last 2 versions, Firefox ESR, not dead, not ie 11"

see package.json "build" script
see browserslist queries

How It Works

vue3-sfc-loader.js = Webpack( @vue/compiler-sfc + @babel )

more details

  1. load the .vue file
  2. parse and compile template, script and style sections (@vue/compiler-sfc)
  3. transpile script and compiled template to es5 (@babel)
  4. parse scripts for dependencies (@babel/traverse)
  5. recursively resolve dependencies
  6. merge all and return the component

Any Questions

💬 ask in Discussions tab

Tweet

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].