All Projects → FranckFreiburger → Http Vue Loader

FranckFreiburger / Http Vue Loader

Licence: mit
load .vue files from your html/js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Http Vue Loader

resloader
🎉A image preloaded plugin and can display the loaded image progress bar
Stars: ✭ 20 (-98.29%)
Mutual labels:  promise, loader
react-nested-loader
The easiest way to manage loaders/errors inside a button. NOT an UI lib.
Stars: ✭ 62 (-94.71%)
Mutual labels:  promise, loader
Vue Element Loading
⏳ Loading inside a container or full screen for Vue.js
Stars: ✭ 234 (-80.03%)
Mutual labels:  loader, vuejs2
Rsup Progress
❤️ A simple progress bar with promises support
Stars: ✭ 290 (-75.26%)
Mutual labels:  promise, loader
Neuron.js
A Full Feature CommonJS Module Manager, Dependency Graph Handler and Loader for Browsers
Stars: ✭ 66 (-94.37%)
Mutual labels:  loader
Callbag Map Promise
Callbag map promise
Stars: ✭ 64 (-94.54%)
Mutual labels:  promise
Basic Vue Chat
Easy to use Vue chat.
Stars: ✭ 64 (-94.54%)
Mutual labels:  vuejs2
Yux Storage
yux-storage 是一个基于 HTML5 IndexedDB 封装的 Web 本地数据离线存储库
Stars: ✭ 64 (-94.54%)
Mutual labels:  promise
Vue Builder Webpack Plugin
Webpack plugin to build vue files automatically
Stars: ✭ 70 (-94.03%)
Mutual labels:  vuejs2
Write
Write data to the file system, creating any intermediate directories if they don't already exist. Used by flat-cache and many others!
Stars: ✭ 68 (-94.2%)
Mutual labels:  promise
Muse Ui
Material Design UI library for Vuejs 2.0
Stars: ✭ 8,302 (+608.36%)
Mutual labels:  vuejs2
Promised Pipe
A ramda.pipe-like utility that handles promises internally with zero dependencies
Stars: ✭ 64 (-94.54%)
Mutual labels:  promise
Extracted Loader
It reloads extracted stylesheets extracted with ExtractTextPlugin
Stars: ✭ 67 (-94.28%)
Mutual labels:  loader
Vueye Table
A data table created using Vue.js
Stars: ✭ 64 (-94.54%)
Mutual labels:  vuejs2
Graphql Batch
A query batching executor for the graphql gem
Stars: ✭ 1,164 (-0.68%)
Mutual labels:  promise
Antsword Loader
AntSword 加载器
Stars: ✭ 1,124 (-4.1%)
Mutual labels:  loader
Emittery
Simple and modern async event emitter
Stars: ✭ 1,146 (-2.22%)
Mutual labels:  promise
Socket.io Rpc
Extend your promises across a network with socket.io
Stars: ✭ 67 (-94.28%)
Mutual labels:  promise
Laravel Vue Tasks
📝 Task app built with Laravel 5.5 and Vue 2
Stars: ✭ 66 (-94.37%)
Mutual labels:  vuejs2
Flowa
🔥Service level control flow for Node.js
Stars: ✭ 66 (-94.37%)
Mutual labels:  promise

🎉 http-vue-loader evolved into vue3-sfc-loader that supports Vue2 and Vue3 🎉

(see the announcement)

http-vue-loader

Load .vue files directly from your html/js. No node.js environment, no build step.

examples

my-component.vue

<template>
    <div class="hello">Hello {{who}}</div>
</template>

<script>
module.exports = {
    data: function() {
        return {
            who: 'world'
        }
    }
}
</script>

<style>
.hello {
    background-color: #ffe;
}
</style>

index.html

<!doctype html>
<html lang="en">
  <head>
    <script src="https://unpkg.com/vue"></script>
    <script src="https://unpkg.com/http-vue-loader"></script>
  </head>

  <body>
    <div id="my-app">
      <my-component></my-component>
    </div>

    <script type="text/javascript">
      new Vue({
        el: '#my-app',
        components: {
          'my-component': httpVueLoader('my-component.vue')
        }
      });
    </script>
  </body>
</html>

More examples

using httpVueLoader()

...
<script type="text/javascript">

    new Vue({
        components: {
            'my-component': httpVueLoader('my-component.vue')
        },
        ...

or, using httpVueLoader.register()

...
<script type="text/javascript">

    httpVueLoader.register(Vue, 'my-component.vue');

    new Vue({
        components: [
            'my-component'
            ]
        },
        ...

or, using httpVueLoader as a plugin

...
<script type="text/javascript">

    Vue.use(httpVueLoader);

    new Vue({
        components: {
            'my-component': 'url:my-component.vue'
        },
        ...

or, using an array

    new Vue({
        components: [
            'url:my-component.vue'
            ]
        },
        ...

Features

  • <template>, <script> and <style> support the src attribute.
  • <style scoped> is supported.
  • module.exports may be a promise.
  • Support of relative urls in <template> and <style> sections.
  • Support custom CSS, HTML and scripting languages, eg. <script lang="coffee"> (see VueLoader.langProcessor).

Browser Support

Chrome Firefox Safari Opera Edge IE
Latest ✔ Latest ✔ ? ? Latest ✔ 9+ ✔

Requirements

Since some browsers do not allow XMLHttpRequest to access local files (Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https), you can start a small express server to run this example.

Run the following commands to start a basic web server:

npm install express
node -e "require('express')().use(require('express').static(__dirname, {index:'index.html'})).listen(8181)"

API

httpVueLoader(url)

url: any url to a .vue file

httpVueLoader.register(vue, url)

vue: a Vue instance
url: any url to a .vue file

httpVueLoader.httpRequest(url)

This is the default httpLoader.

Use axios instead of the default http loader:

httpVueLoader.httpRequest = function(url) {
    
    return axios.get(url)
    .then(function(res) {
        
        return res.data;
    })
    .catch(function(err) {
        
        return Promise.reject(err.status);
    });
}
httpVueLoader.langProcessor

This is an object that contains language processors related to the lang attribute of the <script> section.
The language is a simple function that accepts a script source as argument and returns a javascript script source.

Example - CoffeeScript:

<script src="http://coffeescript.org/v1/browser-compiler/coffee-script.js"></script>
<script src="httpVueLoader.js"></script>

<script>

httpVueLoader.langProcessor.coffee = function(scriptText) {

    return window.CoffeeScript.compile(scriptText, {bare: true});
}

</script>

Then, in you .vue file:

...
<script lang="coffee">

module.exports =
    components: {}
    data: ->
        {}
    computed: {}
    methods: {}

</script>
...

Example - Stylus:

<script src="//stylus-lang.com/try/stylus.min.js"></script>
<script src="httpVueLoader.js"></script>

<script>

httpVueLoader.langProcessor.stylus = function(stylusText) {

    return new Promise(function(resolve, reject) {
        
        stylus.render(stylusText.trim(), {}, function(err, css) {

            if (err) reject(err);
            resolve(css);
        });
    })
}

</script>
...
<style lang="stylus">

    border-radius()
        -webkit-border-radius: arguments
        -moz-border-radius: arguments
        border-radius: arguments

    form input
        padding: 5px
        border: 1px solid
        border-radius: 5px

</style>
...

Sass (SCSS) example. Since sass.compile() is asynchronous, a promise needs to be returned:

<script src="sass.js"></script>
<script src="httpVueLoader.js"></script>

<script>
    httpVueLoader.langProcessor.scss = function (scssText) {
        return new Promise(function(resolve, reject) {
            sass.compile(scssText, function (result) {
                if ( result.status === 0 )
                    resolve(result.text)
                else
                    reject(result)
            });
        });
    }
// ....
...
<style lang="scss">
$font-stack:    Helvetica, sans-serif;
$primary-color: #333;

body {
  font: 100% $font-stack;
  color: $primary-color;
}
</style>

How it works

  1. http request the vue file
  2. load the vue file in a document fragment
  3. process each section (template, script and style)
  4. return a promise to Vue.js (async components)
  5. then Vue.js compiles and cache the component

Notes

The aim of http-vue-loader is to quickly test .vue components without any compilation step.
However, for production, I recommend to use webpack module bundler with vue-loader, webpack-simple is a good minimalist webpack config you should look at.
BTW, see also why Vue.js doesn't support templateURL.

Caveat

Due to the lack of suitable API in Google Chrome and Internet Explorer, syntax errors in the <script> section are only reported on FireFox.

Credits

Franck Freiburger

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].