@bluesyoung/unplugin-json-conf
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

unplugin-json-conf

在运行/打包过程中,加载指定位置的JSON文件的内容作为虚拟模块的默认导出内容

安装

# 选择一个你喜欢的包管理器
# NPM
$ npm install @bluesyoung/unplugin-json-conf --save

# Yarn
$ yarn add @bluesyoung/unplugin-json-conf

# pnpm
$ pnpm add @bluesyoung/unplugin-json-conf

使用

项目代码相关

// 注入环境变量(json 配置文件的路径)
VITE_JSON_CONF_URL = './data.json'

// 注入 env.d.ts
declare module 'virtual:json-conf' {
  const src: Record<string, any>
  export default src
}
// 使用
import json from 'virtual:json-conf';

配置相关

Vite

// vite.config.ts
import JsonConf from '@bluesyoung/unplugin-json-conf/vite'

export default defineConfig({
  plugins: [
    JsonConf({ /* options */ }),
  ],
})

Example: playground/


Rollup
// rollup.config.js
import JsonConf from '@bluesyoung/unplugin-json-conf/rollup'

export default {
  plugins: [
    JsonConf({ /* options */ }),
  ],
}


Webpack
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('@bluesyoung/unplugin-json-conf/webpack')({ /* options */ })
  ]
}


Nuxt
// nuxt.config.js
export default {
  buildModules: [
    ['@bluesyoung/unplugin-json-conf/nuxt', { /* options */ }],
  ],
}

This module works for both Nuxt 2 and Nuxt Vite


Vue CLI
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('@bluesyoung/unplugin-json-conf/webpack')({ /* options */ }),
    ],
  },
}


Package Sidebar

Install

npm i @bluesyoung/unplugin-json-conf

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

20.4 kB

Total Files

28

Last publish

Collaborators

  • bluesyoung