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

requirejs-vue

v1.1.5

Published

An AMD loader for Vue components 🤘🏽. Pug 🐶 supported.

Downloads

1,159

Readme

requirejs-vue

ECMAScript 5.1 Github file size

A Vue.js Single File Components loader plugin for RequireJS. One-file, browser or server, no additional fats, es5+ compatible, no babels, gluten-free.

On browser-side it uses XMLHttpRequest to fetch the .vue files, so you can only fetch files that are on the same domain as the html page. Most browsers place restrictions on using XMLHttpRequest from local file URLs, so use a web server to serve your .vue files.

The server-side building with RequireJS Optimizer r.js also available and works well.

Plugin supports pug templates. Provide pug parser via module config. Tested with browser-side pug renderer.

Since another templating engines or css preprocessors (like less/sass) not available as maintained AMD modules there are no plans to support them. Feel free to write your own 😉

Install

Via package manager

To install with Bower:

  bower install requirejs-vue

With yarn

yarn add requirejs-vue

Or good ol' npm:

npm install --save requirejs-vue

Manual download

Download the latest version.

Usage

Setup loader in RequireJS path like this:

...
    paths: {
        'Vue': 'path to Vue.js',
        'vue': 'path to requirejs-vue'
    },
    config: {
        'vue': {
            'pug': 'browser-pug',
            'css': 'inject'
            'templateVar': 'template'
        }
    }
...

Reference Vue file via the vue!. For example, to load the component.vue file that is in your baseUrl directory:

require(['vue!component'], function (component) {
	//
});

You can specify any alias for loader but update paths alias too.

Configuration

Inside loaded file reference template by templateVar variable. Stylesheets controlled by css configuration value. Currently only global styles supported. Content of template will be cleared from whitespaces and comments. Nested template tags supported.

Loader support .vue and .html files.

css

String | Function, default: inject

Strategy to deal with component stylesheets. Variants: * inject - appending styles in new <style> tag to document.body * skip - do not process component css. Default action for r.js build mode. * fn(style, option{name}) - callback function for css aggregation. style contains actual component style content, option.name hold component file reference

pug

String, default: <none>

Module name for Pug template rendering.

templateVar

String, default: template

Represent component template as templateVar variable in script closure.

Basic usage

Sample .vue file supported by loader:

<template>
    <div v-cloak>Vue-demo component root</div>
</template>
<style>
    /* global styles */
    [v-cloak] {
        display: none;
    }
</style>
<script>
define(['Vue'], function(vue){
  Vue.component('vue-demo', {
    template: template
  })
});
</script>

Pug templates

Using browser-pug it is possible to transpose basic pug markup as Vue template. To achieve do next steps:

  1. Install browser-pug plugin
yarn add browser-pug
  1. Setup module paths and configs in your RequireJS config:

    ... paths: { ... Vue: 'node_modules/vue/dist/vue.min', 'vue-loader': 'node_modules/requirejs-vue/requirejs-vue', 'browser-pug': 'mode_modules/browser-pug/browser-pug' ... }, config: { 'vue-loader': { pug: 'browser-pug' } } ...

  2. Mark template as pug-able in your Vue component:

<template lang="pug">
div
	p Here comes the magic
	a(v-bind:href="dummyLink") Follow us
</template>
<script>
  define(['Vue'], function(Vue){
    new Vue({
      template: template,
      data: {
        dummyLink: 'http://bit.ly/naked_truth_about_javascript'
      }
    }).$mount('#app');
  });
</script>

Note: be aware of using this heavily in production may slow down your app initialization due client-side .pug rendering

Server-side building with r.js

Plugin supports RequireJS Optimizer. Follow the usual r.js workflow: specify build config in build.js like:

{
	baseUrl: './',
	name: 'init',
	out: './dist.js',
	findNestedDependencies: true,
	optimize: 'none',
	paths: {
	  Vue: 'node_modules/vue/dist/vue.min',
	  vue: 'node_modules/requirejs-vue/requirejs-vue',
	  app: 'your-entry-point'
}
  }

and then run builder:

r.js -o build.js

For advanced usage see demo project.

License

MIT © 2017 vikseriq