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 🙏

© 2024 – Pkg Stats / Ryan Hefner

flexivue

v0.0.10

Published

Integrate Vue.js with Rails views and webpacker.

Downloads

4

Readme

Flexivue

Integrate Vue.js with Rails views and webpacker.

Flexivue is a flexible tool to use Vue with Rails. The benefits:

  • Lets you both use Rails views and Vue components
  • Lets you use ES6, TypeScript, CoffeeScript
  • Supports Webpacker

Get started

Webpacker provides modern JS tooling for Rails. So we need to create a Rails project which which supports Vue first.

1. Create a new Rails app

$ rails new my-project --webpack=vue
$ cd my-project

2. Yarn add flexivue

$ yarn add flexivue

3. Use Flexivue webpack-helpers to automatically load instances files from a folder in your app

// app/javascript/packs/application.js
import Vue from "vue/dist/vue.esm"
import { Application } from "flexivue"
import { definitionsFromContext } from "flexivue/webpack-helpers"

const application = Application.initialize({ vue: Vue })
const context = require.context("instances", true, /\.js$/)

// Or addEventListener("turbolinks:load") if you use turbolinks
document.addEventListener("DOMContentLoaded", () => {
  application.load(definitionsFromContext(context))
})

4. Create a Vue instance

// app/javascript/instances/hello.js
import { Instance } from "flexivue"

export default class extends Instance {
  data = {
    name: "Flexivue"
  }
}

5. Link the JavaScript pack in Rails view using javascript_pack_tag helper

<!-- app/views/layout/application.html.erb in Head tag -->
<%= javascript_pack_tag 'application' %>

6. Render instance in a Rails view

<div instance="hello">
  <h1> Hello {{name}}</h1>
</div>

7. You can also use Vue components

<!-- app/javascript/components/counter.vue -->
<template>
  <div class="counter">
    <span>{{count}}</span>
    <button @click="inc">+</button>
  </div>
</template>

<script>
  export default {
    data() {
      return { count: 0 }
    },
    methods: {
      inc() { this.count++ }
    }
  }
</script>

8. Then update hello instance

import { Instance } from "flexivue"
import Counter from "../components/counter.vue"

export default class extends Instance {
  data = {
    name: "Flexivue"
  }

  components = {
    "counter": Counter
  }
}

9. Render instance with component in a Rails view

<div instance="hello" data={ greet: "Welcome!" }>
  <h1> Hello {{name}} </h1>
  <h1> {{greet}} </h1>
  <counter></counter>
</div>

Instance file naming

Instance file Name | Instance name in Views -----|----- app/javascript/instances/sampleinstance.js | <div instance="sampleinstance"> app/javascript/instances/sample_instance.js | <div instance="sample_instance"> app/javascript/instances/SampleInstance.js | <div instance="SampleInstance"> app/javascript/instances/namespace/sampleinstance.js | <div instance="namespace--sampleinstance">

Typescript support

Flexivue supports Typescript, just fell free to use it.

License

Released under the MIT license. See LICENSE file for details.