All Projects → egoist → vite-plugin-compile-time

egoist / vite-plugin-compile-time

Licence: MIT license
Some compile-time magic for your Vite project

Programming Languages

typescript
32286 projects
HTML
75241 projects

Labels

Projects that are alternatives of or similar to vite-plugin-compile-time

win7
Yet another OS preview via web technologies focused on Microsoft Windows 7.
Stars: ✭ 93 (-1.06%)
Mutual labels:  vite
mongood
A MongoDB GUI with Fluent Design
Stars: ✭ 674 (+617.02%)
Mutual labels:  vite
vue-devui-early
Vue3版本的DevUI组件库。本仓库已迁移至:https://github.com/DevCloudFE/vue-devui
Stars: ✭ 39 (-58.51%)
Mutual labels:  vite
fast-vite-nestjs-electron
Vite + Electron + Nestjs with esbuild, crazy fast! ⚡
Stars: ✭ 128 (+36.17%)
Mutual labels:  vite
soybean-admin
A fresh and elegant admin template, based on Vue3,Vite3,TypeScript,NaiveUI and UnoCSS [一个基于Vue3、Vite3、TypeScript、NaiveUI 和 UnoCSS的清新优雅的中后台模版]
Stars: ✭ 2,322 (+2370.21%)
Mutual labels:  vite
vite-plugin-restart
Custom files/globs to restart Vite server
Stars: ✭ 92 (-2.13%)
Mutual labels:  vite
fastadmin
vue3 + element-plus fast admin scaffold, 基于vue3和ElementPlus的中后台快速应用脚手架
Stars: ✭ 50 (-46.81%)
Mutual labels:  vite
vite-react-electron
Electron + Vite + React + Sass boilerplate.
Stars: ✭ 700 (+644.68%)
Mutual labels:  vite
vital
Starter template for Vite with React (TypeScript). Supports Tailwind with CSS-Modules. Jest and @react/testing-library configured and ready to go. Also ESLint, Prettier, Husky, Commit-lint and Atomic Design for components.
Stars: ✭ 151 (+60.64%)
Mutual labels:  vite
iro
IRO - Amazing Color Tools. Color Convert HEX, RGB, HSL and CMYK. Color Inspection with Camera.
Stars: ✭ 103 (+9.57%)
Mutual labels:  vite
webpack-to-vite
Convert a webpack/vue-cli project to vite project. 将 webpack/vue-cli 项目转换为 vite 项目。
Stars: ✭ 603 (+541.49%)
Mutual labels:  vite
promotion-web
基于React: v18.x.x/Webpack: v5.x.x/React Router v6.x.x/ Antd: v5..x.x/Fetch Api/ Typescript: v4.x.x 等最新版本进行构建...
Stars: ✭ 374 (+297.87%)
Mutual labels:  vite
vue-lite-admin
a lite vue3.0 admin template,there is no typescript and vuex (但注释挺全)
Stars: ✭ 67 (-28.72%)
Mutual labels:  vite
Admin-Frame-Vue3
基于Vue3 + Element-Plus + Vite 开发的中/后台管理系统
Stars: ✭ 181 (+92.55%)
Mutual labels:  vite
vite-app-ios
Vite Official App for iOS
Stars: ✭ 40 (-57.45%)
Mutual labels:  vite
vue-component-lib-starter
A bare-bones example of creating your own Vue component library.
Stars: ✭ 221 (+135.11%)
Mutual labels:  vite
tailwindcss
Add Tailwind CSS to your Svelte project
Stars: ✭ 583 (+520.21%)
Mutual labels:  vite
preview-pro
Use pro-layout in vitejs. preview https://sendya.github.io/preview-pro/index.html
Stars: ✭ 71 (-24.47%)
Mutual labels:  vite
vite-electron-esbuild-starter
⚡️The electron starter using Vite and esbuild to fast development.
Stars: ✭ 52 (-44.68%)
Mutual labels:  vite
vite-plugin-dts
A vite plugin for generating `.d.ts` files.
Stars: ✭ 539 (+473.4%)
Mutual labels:  vite

💛 You can help the author become a full-time open-source maintainer by sponsoring him on GitHub.


vite-plugin-compile-time

npm version npm downloads

Use this plugin to generate code at compile time or get data at compile time in your Vite projects.

Install

npm i vite-plugin-compile-time -D
import { defineConfig } from "vite"
import compileTime from "vite-plugin-compile-time"

export default defineConfig({
  plugins: [compileTime()],
})

Usage

Compile-time data:

// get-data.ts
import fs from "fs"

export default async () => {
  const post = await fs.promises.readFile("./post.md", "utf8")
  return {
    data: { post },
  }
}

// get the data at compile time
const data = import.meta.compileTime("./get-data.ts")
assert.deepEqual(data, { post: "....." })

Compile-time code:

// generate-code.ts
export default async () => {
  return {
    code: `count++`,
  }
}

// insert the generated code at compile time
let count = 0
import.meta.compileTime("./generate-code.ts")
assert.equal(count, 1)

API

Use import.meta.compileTime to get compile-time data or code.

declare interface ImportMeta {
  compileTime: <T>(file: string) => T
}

You should return a default export with object containing code or data property:

import {
  CompileTimeFunctionArgs,
  CompileTimeFunctionResult,
} from "vite-plugin-compile-time"

export default async (
  args: CompileTimeFunctionArgs,
): CompileTimeFunctionResult => {
  return {
    data: {
      hello: "world",
    },
    // Trigger rebuild when watched files change
    watchFiles: ["/absolute/path"],
  }
}

See the type docs on paka.dev.

Sponsors

sponsors

License

MIT © EGOIST

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].