Giter VIP home page Giter VIP logo

gulp-vue-module's Introduction

gulp-vue-module

Gulp plugin for Vue.js *.vue component file complie to AMD / CMD / CommonJS module.

Now, You can use Require.js / Sea.js ... etc. Front-end Module loader load Vue Component, not use Webpack and vue-loader.

Usage

$ npm install gulp-vue-module --save-dev

Gulpfile.js :

var fs        = require('fs');
var path      = require('path');
var gulp      = require('gulp');
var rename    = require('gulp-rename');
var VueModule = require('gulp-vue-module');

gulp.task('vue', function() {
    return gulp.src('./vue/**/*.vue')
                .pipe(VueModule({
                    debug : true
                }))
                .pipe(rename({extname : ".js"}))
                .pipe(gulp.dest("./dist"));
});

gulp.task('default', ['vue']);

app.vue :

tag order : <style> > <template> > <script>, <tempate> tag must be at <script> tag before.

<style lang="scss">
$color:red;

.card {
    backround: $color;
    
    > .head {
        color: $color;
        background: yellow;
    }
}
</style>

<template>
    <div class="app" @click="click">
        <p>{{a}}</p>
        <list-component :msg="message"></list-component>
    </div>
</template>

<script>
    var Vue           = require("vue");
    var listComponent = require('component/list');

    module.exports = Vue.extend({
        data : function() {
            return {
                id      : 23456,
                message : 'Message'
            }
        },
        methods : {
            click : function() {
                console.log("click()");
            }
        },
        components: {
            'list-component' : listComponent
        },
        template : '__template__'
    });
</script>

<template> tag unsupport set lang attribute, support set include="/path/to/xxx.xxx" attribute.

<script> tag unsupport set lang attribute, so you can't use ES6 syntax;

<style> tag support set lang="css|scss|sass" attribute, and support set href="/path/to/xxx.(css|scss|sass)" attribute link CSS file.

You can use <header-comment> tag insert the header comments

Output :

define(function(require, exports, module){
    // require.loadCSS() need you implement this function
    require.loadCSS({content : ".card{backround:red}.card>.head{color:red;background:yellow}"});

    var Vue           = require("vue/all");
    var listComponent = require('component/list');

    module.exports = Vue.extend({
        data : function() {
            return {
                id      : 23456,
                message : 'Message'
            }
        },
        methods : {
            click : function() {
                console.log("click()");
            }
        },
        components: {
            'list-component' : listComponent
        },
        template : '<div class="app" @click="click"><p>{{a}}</p><list-component :msg="message"></list-component></div>'
    };
});

require.loadCSS() implement example :

require.loadCSS = function(config) {
    var head = document.getElementsByTagName("head")[0];

    if (config.content) {
        var style  = document.createElement('style');
        style.type = 'text/css';
        
        if (style.styleSheet) { // for IE
            style.styleSheet.cssText = config.content;
        } else {
            style.innerHTML = config.content;
        }

        head.appendChild(style);
        callback();
    }
    else if (config.url) {
        var link  = document.createElement('link');

        link.href = config.url;
        link.rel  = 'stylesheet';
        link.type = 'text/css';
        head.appendChild(link);
    }
};

Options

{
    debug              : false,             // Debug mode
    amd                : false,             // AMD style, Define module name and deps
    define             : true,              // Using define() wrapper the module, false for Node.js (CommonJS style)
    defineName         : false,             // Define the module name
    indent             : '    ',            // Indent whitespace
    headerComment      : true,              // Using <header-comment> Insert the header comments
    templateReplaceTag : '__template__',    // vue component template replace tag
    loadCSSMethod      : 'require.loadCSS', // define the load css method for require
    externalRequire    : false              // don't pass require as a parameter
}

You can set externalRequire to true and inject vue into the file insted of requiring it internally.

Changes

Change logs

License

The MIT license.

Copyright (C) 2016 Pandao

gulp-vue-module's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gulp-vue-module's Issues

v-bind:class={'box-default': isDefault} giving error

Binding a class attribute in the template like

v-bind:class={'box-default': isDefault} 

produces error
- avoid using JavaScript keyword as property name: "default" in expression :class="{&#39;box-default&#39;: isDefault}"

where should I implement require.loadCSS()?

I can't understant why should I implement a method like require.loadCSS
Is it necessary or just optional when I am running an gulp compile with *.vue file?
and If we must implement this method ,where should I put it in my code?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.