vuegister-plugin-babel

0.2.1 • Public • Published

vuegister-plugin-babel npm version build status

Vuegister plugin for Babel.

Issues with the output should be reported on the Babel issue tracker.

Install

npm i vuegister-plugin-babel -D

Test suite example

To run test suite create test.js and MyComponent.vue files inside your test folder.

Content of the test.js file:

const assert = require('chai').assert;
const Vue = require('vue/dist/vue.common')
const MyComponent = require('./MyComponent.vue').default
 
describe('MyComponent', () => {
  it('has a created hook', () => {
    assert.isFunction(MyComponent.created)
  })
 
  it('sets the correct default data', () => {
    assert.isFunction(MyComponent.data)
    const defaultData = MyComponent.data()
    assert.strictEqual(defaultData.message, 'hello!')
  })
 
  it('correctly sets the message when created', () => {
    const vm = new Vue(MyComponent).$mount()
    assert.strictEqual(vm.message, 'bye!')
  })
})

Content of the MyComponent.vue file:

<template>
  <span>{{ message }}</span>
</template>
<script lang="babel">
  export default {
    data () {
      return {
        message: 'hello!'
      }
    },
    created () {
      this.message = 'bye!'
    }
  }
</script> 

Install jsdom-global and run tests with:

npm i jsdom jsdom-global -D
mocha -r jsdom-global/register -r vuegister/register

Caveats

Babel transpiles this code:

export default {
  data () {
    return {
      message: 'hello!'
    }
  }
}

into this:

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = {
  data() {
    return {
      message: 'hello!'
    };
  }
};

So now you have to call .default in Node.js code:

var foo = require('foo').default

Tests

To run the test suite, install development dependencies and execute:

npm run coverage

License

Distributed under MIT License.

Readme

Keywords

Package Sidebar

Install

npm i vuegister-plugin-babel

Weekly Downloads

8

Version

0.2.1

License

MIT

Last publish

Collaborators

  • iatsiuk