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

require-extension-vue

v1.3.2

Published

A require hook for loading single-file vue component in Node with Browser environment.

Downloads

19

Readme

npm npm npm Travis CI bitHound Code Greenkeeper badge Twitter

require-extension-vue

A require hook for loading single-file vue component in Node with Browser environment.

What's it?

1. Your project is running in Node with Browser environment. (Electron etc.)

2. The expected feature you want, like runtime:

// app.vue
<script>
export default {
    // ...
};
</script>
<template>
    // ...
</template>
<style>
    // ...
</style>
import 'require-extension-vue';
// From now on, you can import or require a single-file vue component.
import app from './app.vue';
// This object is what you export. (include attributes: data, computed, created etc.)
// <template> will be exported in app.template as String.
// <style> will be appended to document.head, if you have Browser environment.

3. Do what you like.

new Vue(app).$mount('app');

Getting started

$ npm install --save require-extension-vue

or, You want a quick start. (use-vue)

Usage

Simple

import 'require-extension-vue';
import app from './app.vue';

new Vue(app).$mount('app');

Config

import loader from 'require-extension-vue';

#loader.style.register

Register language to compile style.

loader.style.register('scss', ( content, filePath, index ) => {
    // compile
    return content;
});
<style lang="scss">
    // sass code
</style>

#loader.style.set

Set a default language.

loader.style.set('scss');
<style>
    // No need to Declare lang="scss" any more
    // sass code
</style>

#loader.style.exports

Append styles to where you like.

loader.style.exports(function ( style, { index, styles, filePath } ) {
    document.head.appendChild(style);
});

#sync

Compile handler should return content sync, includes <template>, <script> and <style>.

#async

Deprecated, @see

API

#Register

register ( lang : String, handler : Function ) => this

handler ( content : String, filePath : String, index : Number ) => content : String

loader.style.register / loader.script.register / loader.template.register

#Set

set ( lang : String ) => this

loader.style.set / loader.script.set / loader.template.set

#Exports

exports ( handler : Function ) => this

handler ( style : Element, options : Object ) { this : Vue } => void

options { index : Number, styles : Array<Element>, filePath : String }

loader.style.exports

Notice

In the following case, as the import synax like Variable Hosting:

import loader from 'require-extension-vue';
loader.script.register('babel', handler).set('babel');
import app from './app.vue';

The above case is equal to the following case:

import loader from 'require-extension-vue';
import app from './app.vue';
// Your config behavior is after require, so it is not working.
loader.script.register('babel', handler).set('babel');

There're two way to avoid:

You can use require instead of import.

import loader from 'require-extension-vue';
loader.script.register('babel', handler).set('babel');
let app  = require('./app.vue');

Put the config behavior in one file.

import 'require-extension-vue';
import './require-extension-vue-config.js';
import app from './app.vue';
// require-extension-vue-config.js
let loader = require.extensions['.vue'];
loader.script.register('babel', handler).set('babel');

Scoped

Support scoped, like vue-loader. @see

#Mind you

This feature require css-what.

But, it is defective. @see

If your class name includes # (>, etc), it can not parse to correct AST selector.

Todo

  • source map.

License

MIT