npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vues6

v0.2.0

Published

Use ES6 classes to define Vue.js components - without TypeScript!

Readme

VuES6 - Use ES6 Classes to Define Vue.js Components

This is a small utility library that adds a mechanism for defining Vue components as ES6 templates, but in vanilla JavaScript, such that they don't have to be compiled ahead of time.

Yes, .vue files provide this ability, but sometimes I don't want to set up an entire compiled repo for a small Vue.js project, but I still want Vue.js components in the form of classes. This allows ES6 classes to be turned into Vue components at runtime.

Installation

Just include the vues6.js file as a module after Vue:

<script src="vues6.js" type="module"></script>

Usage

First, we need to define the components. This uses all the same parts as the normal object-literal format, just in the form of an ES6 class. Here's a very basic example component:

import { Component } from './vues6.js'

const template = `
<div>
	<h1>{{ message }} (Changes: {{ changes }})</h1>
	<h2>{{ tagline }}</h2>
	<button type="button" @click="onClick">Click Me!</button>
	<input type="text" v-model="message">
</div>
`

export default class HelloWorldComponent {
	static get selector() { return 'hello-world' }
	static get props() { return ['tagline'] }
	static get template() { return template }

	message = 'Hello World'
	changes = 0

	onClick() {
		this.message += '!'
	}

	watch_message(new_message, old_message) {
		this.changes += 1
	}
}

There are a few important things to note here:

  • The static get selector() defines the HTML selector used to implement the component (e.g. <hello-world></hello-world>).

  • Properties of the class are accessible in the template.

  • Methods of the class are accessible in the template.

    Important Note: VuES6 uses Object.getOwnPropertyNames to determine the methods to bind to the Vue.js component. Thus, inherited methods are not supported at this time.

  • Class methods beginning with watch_ will not be made available as normal methods, but are instead watchers. In this example watch_message() defines a watcher on the message field.

  • There is no data() function, however the Vue lifecycle functions can be hooked into by implementing the following methods on your class:

    • vue_on_create
    • vue_on_update
    • vue_on_mount
    • vue_on_destroy

This is the equivalent of writing this:

Vue.component('hello-world', {
    props: ['tagline'],
    template: `
        <div>
            <h1>{{ message }} (Changes: {{ changes }})</h1>
            <h2>{{ tagline }}</h2>
            <button type="button" @click="onClick">Click Me!</button>
            <input type="text" v-model="message">
        </div>
	`,
    data: function() {
        return {
            message: 'Hello World',
            changes: 0
        }
    },
    watch: {
        message: function(new_message, old_message) {
            this.changes += 1
        }
    },
    methods: {
        onClick: function() {
            this.message += '!'
        }
    }
})

but, without all the cludgy Vue-specific object syntax.

Now, we can use them in the Vue app like normal, as long as the components are loaded by the VuES6Loader. In your main JavaScript:

import { HelloWorldComponent } from './HelloWorld.component.js'
import VuES6Loader from './vues6.js'

// You could define this in a separate module
const components = {
    HelloWorldComponent
}

// Load the component classes into Vue.component
const loader = new VuES6Loader(components)
loader.load()

const app = new Vue({
    el: '#my-vue-app',
})

For a complete example, see the example/ directory.

License

Copyright © 2020 Garrett Mills

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.