Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/iosamuel/vite-plugin-vue-sfc-in-js

Vue SFC in JS files
https://github.com/iosamuel/vite-plugin-vue-sfc-in-js

Last synced: about 2 months ago
JSON representation

Vue SFC in JS files

Lists

README

        

# Vue SFC in JS 🔰

```bash
npm install vite-plugin-vue-sfc-in-js
```

---

The objective of this plugin is to allow developers to write SFCs inside JS files, similar to JSX... in some way.

For example:

```js
export const ClearCartIcon = (












);

export const CartIcon = (


import {ref} from "vue"; console.log("Hello!"); const refVar = ref("");











);
```

As you can see, the main advantage here is that we can export multiple components from the same `.js` file and use it like a normal component inside other Vue components.

```vue

import { ClearCartIcon, CartIcon } from "./Icons";

```

## Usage

Add this plugin to `vite.config.js`

```js
import { defineConfig } from "vite";
import vueSFCinJS from "vite-plugin-vue-sfc-in-js";
export default defineConfig({
plugins: [vueSFCinJS()],
});
```

And start writing SFC in your JS files, by using a similar syntax as JSX, just make sure to wrap your SFCs in a `` Tag.

You can use either a `.js` or a `.vjs` file if you feel it more convenient.

```js
export const CartIcon = (

// Can use Script


Can use Template


/* not implemented */

);
```

## 🤔 Why?

For now, this is just a very naive and simplistic POC to see if actually more Devs would like and use this kind of solution.

So if you actually like it, please remember to ⭐️ the repo and 📦 `npm install` the heck out of it.

### Problem to solve

In Vue world, for example if you want to have multiple Icons and use them, you would need to create an `Icons` folder and create multiple `.vue` files, one per icon.

### Solution

With VJS you only need an `Icons.[v]js` file and export all the components you want using JS + SFC syntax!

## Author

Samuel Burbano - @iosamuel

## License

ISC