1.0.1 • Published 1 year ago

rollup-plugin-json-cmd v1.0.1

Weekly downloads
-
License
Apache License 2....
Repository
github
Last release
1 year ago

一个处理JSON文件的插件

安装

npm i -D rollup-plugin-json-cmd

使用方法

假设一个vue项目

import { fileURLToPath, URL } from 'node:url'

import vue from '@vitejs/plugin-vue'
import JsonCmdPlugin from 'rollup-plugin-json-cmd'
import { defineConfig } from 'vite'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(), JsonCmdPlugin("build.json")],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:8081',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})

src目录下创建一个build.json文件:

{
    "git-branch": "git branch --show-current",
    "git-commit": "git rev-parse HEAD",
    "time": "date '+%Y_%m_%d %H:%M:%S'"
}

使用效果(main.ts):

import build from '@/build.json'

console.log(build)
1.0.1

1 year ago

1.0.0

1 year ago