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

vue-sfc-split

v1.0.1

Published

Convert SFCs for use without build

Downloads

6

Readme

vue-sfc-split

Convert SFCs for use without build

What it does

  • Converts .vue files into .js and .css files
  • Includes template into script
  • Auto-attaches generated css file
  • Preserves scoped styles
  • Supports SCSS
  • Maintains structure
  • Rewrites imorts

Installation & Usage

Global

Install:

npm i -g vue-sfc-split

Run from project root:

vue-sfc-split

Local (npm scripts)

Install:

npm i vue-sfc-split

Add npm script to package.json:

"scripts": {
  "split": "vue-sfc-split"
},

Run from project root:

npm run split

Options

--entry starting directory

--publicPath index of application

--ignore patterns to ignore directories

--noscope ignore scoped css, and treat it like usual css

--alias alias for import rewriting

--dest destination folder

--entry

Starting point directory from which .vue files will be targeted recursively

Defaults to current directory

vue-sfc-split --entry=src

--publicPath

Directory where your index.html will live

Style attachment paths will be relative to this

Defaults to same as entry

vue-sfc-split --publicPath=.

--ignore

Comma separated list of glob patterns

node_modules is always ignored

vue-sfc-split --ignore=directory/*,directory-recursive/**

--noscope

If this is specified scoped css will have no effect, all styles will be treated as unscoped

vue-sfc-split --noscope

--alias

Comma separated alias:replacement pairs to be rewritten in import statements

Resulting paths will be relative to the current module

vue-sfc-split --alias=@:src/components

--dest

Where the output files will go

Default: dest/

Set this to an empty string to create .js and .css files next to original .vue files

vue-sfc-split --dest=""

Scope

Scoped styles are processed similarly to how vue does it

Custom data-scope-* attribute will be added to scoped style selectors and template elements

Scope name is created based on file name and its path, keeping generated scope names predictable and non-duplicating

For example this in file hello.vue

<div>Hola</div>
<style scoped>
div {
  color: pink;
}
</style>

Will get converted to this

<div data-scope-hello>Hola</div>
<style scoped>
div[data-scope-hello] {
  color: pink;
}
</style>

This can be disabled by specifying --noscope

Imports

In the output files all .vue imports will automatically be rewritten to target newly created .js files instead

Style attachment

Generated .css files will be automatically attached from generated .js files in this manner:

fetch('hello.css')
  .then(res => res.text())
  .then(style => document.head.insertAdjacentHTML('beforeend', '<style>'+style+'</style>'))

I/O example

Input

hello.vue:

<template>
   <div class="container">
      <h1>{{text}}</h1>
      <Two />
   </div>
</template>

<script>
import Two from './two.vue'

export default {
   name: 'One',
   components: { Two },
   data() {
      return {
         text: 'Hello from component One'
      }
   },
}
</script>

<style scoped>
.container {
   background: silver;
}
</style>

Output

hello.js:

import Two from './two.js'

export default {
  template: `
<div class="container" data-scope-hello>
   <h1>{{text}}</h1>
   <Two></Two>
</div>`,
   name: 'One',
   components: { Two },
   data() {
      return {
         text: 'Hello from component One'
      }
   },
}

// attach styles
fetch('hello.css').then(res => res.text()).then(style => document.head.insertAdjacentHTML('beforeend', '<style>'+style+'</style>'))

hello.css

.container[data-scope-hello] {
   background: silver;
}