0.5.0 • Published 7 years ago

ko-component-compiler v0.5.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

Knockout Component Compiler

What is Knockout Component?

  • Let you write component in single file just like vue component.
  • Easy to write a component and no need to care about register.
<template>
    <div class="btn">
        <icon k-name="icon" class="btn-icon"></icon>
        <span data-bind="text: text" class="btn-text"></span>
    </div>
</template>

<style scoped>
    .btn {
        /* btn style goes here */
    }
</style>

<script>
    export default {
        constructor: function (opts, info) {
            this.text = ko.observable(opts.text);
            this.icon = ko.observable(opts.icon);
        },

        defaults: {
            text: 'Button'
        },

        mixins: [],

        methods: {}
    };
</script>

API

var compiler = require('ko-component-compiler');

compiler.compile('code', function (err, result) {

    // component style template and script wrapped as single file
    console.log(result);
});

Rollup.js

Install packages:

# rollup plugins
$ npm install rollup-plugin-ko
$ npm install rollup-plugin-babel
$ npm install rollup-plugin-commonjs
$ npm install rollup-plugin-node-resolve

# peer deps
$ npm install inject-css
$ npm install robust-mixin
var fs = require('fs');
var rollup = require('rollup');
var ko = require('rollup-plugin-ko');
var babel = require('rollup-plugin-babel');
var commonjs = require('rollup-plugin-commonjs');
var nodeResolve = require('rollup-plugin-node-resolve');

rollup.rollup({
    entry: './src/main.js',
    plugins: [
        nodeResolve({ jsnext: true, main: true }),
        commonjs(),
        ko(),
        babel({
            presets: [
                'es2015-rollup'
            ]
        })
    ]
})
.then(function (bundle) {
    var result = bundle.generate({
        format: 'iife'
    });

    fs.writeFileSync( './dest/app.js', result.code );
})
.catch(function (err) {
    console.log(err);
});
0.5.0

7 years ago

0.4.11

9 years ago

0.4.10

9 years ago

0.4.9

9 years ago

0.4.8

9 years ago

0.4.7

9 years ago

0.4.6

9 years ago

0.4.5

9 years ago

0.4.4

9 years ago

0.4.3

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.12

10 years ago

0.3.11

10 years ago

0.3.10

10 years ago

0.3.9

10 years ago

0.3.8

10 years ago

0.3.7

10 years ago

0.3.6

10 years ago

0.3.5

10 years ago

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago