@hebilicious/extract-sfc-block
Extract custom blocks from `.vue` files.
3,433
116
| Install | |
|---|---|
npm install @hebilicious/extract-sfc-block |
|
| Latest Version: | 0.3.4 |
| Vue: | 3 |
| License: | MIT |
| Last Updated: | Oct 25, 2026 |
| Links: | GitHub · npm |
Maintainer: hebilicious
Extract SFC Server
Extract custom blocks from .vue files.
Install
npm i -D @hebilicious/extract-sfc-block
Usage
Add to your vite configuration :
import ExtractSFCBlock from "@hebilicious/extract-sfc-block"
const VitePlugin = ExtractSFCBlock({
output: "server/.generated", // This is relative to the vite config directory.
sourceDir: "pages", // This is relative to the vite config directory.
blockType: "server", // This will match <server></server> blocks.
defaultPath: "api" // This will only be used if no path attribute is provided.
})
With a SFC [sourceDir]/hello.vue :
<server lang="ts">
const message = "Hello World!!!"
</server>
<template>
<div> This is a template.</div>
</template>
This plugin will create a [output]/[defaultPath]/hello.ts file:
const message = "Hello World!!!"
The file extension will use the lang attribute, or default to .ts.
Custom Path
You can customize the output path at the block level:
<server lang="ts" path="somewhere/else/another-message">
const message = "Hello World!!!"
</server>
<template>
<div> This is a template.</div>
</template>
This plugin will create a somewhere/else/another-message.ts file:
const message = "Hello World!!!"
TODO
- Support multiple server blocks in a single file
- Refactor to unplugin
- Write tests
- Write docs
Related Packages
@hebilicious/form-actions-nuxt
5,110
136
@hebilicious/server-block-nuxt
4,102
116
@hebilicious/authjs-nuxt
16,912
243
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 0.3.4 | ^3.3.4 | MIT | |
| 0.3.3 | ^3.3.4 | MIT | |
| 0.3.2 | ^3.3.4 | MIT | |
| 0.3.1 | ^3.3.4 | MIT | |
| 0.3.0 | ^3.3.4 | MIT | |
| 0.2.0 | ^3.3.4 | MIT | |
| 0.1.0 | ^3.3.4 | MIT | |
| 0.0.5 | ^3.3.4 | MIT | |
| 0.0.3 | ^3.3.4 | MIT |