Home

Awesome

unplugin-config

npm downloads javascript_code style

<div align='center'> <b>English</b> | <a href="README.zh-cn.md">简体中文</a> <br> </div>

A tool that generates configuration files for web applications, allowing customization of global variables that can be externally modified without the need for repackaging.

Features

Install

npm i unplugin-config
<details> <summary>Vite</summary><br>
// vite.config.ts
import ConfigPlugin from "unplugin-config/vite";

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

Example: playground/

<br></details>

<details> <summary>Rollup</summary><br>
// rollup.config.js
import ConfigPlugin from "unplugin-config/rollup";

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

<br></details>

<details> <summary>Webpack</summary><br>
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require("unplugin-config/webpack")({ /* options */ })
  ]
};

<br></details>

<details> <summary>Nuxt</summary><br>
// nuxt.config.js
export default {
  buildModules: [
    ["unplugin-config/nuxt", { /* options */ }],
  ],
};

This module works for both Nuxt 2 and Nuxt Vite

<br></details>

<details> <summary>Vue CLI</summary><br>
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require("unplugin-config/webpack")({ /* options */ }),
    ],
  },
};

<br></details>

<details> <summary>esbuild</summary><br>
// esbuild.config.js
import { build } from "esbuild";
import ConfigPlugin from "unplugin-config/esbuild";

build({
  plugins: [ConfigPlugin()],
});

<br></details>

Configuration

The Options object contains the following properties:

Application Options (appName and baseDir)

Configuration File Options (configFile)

HTML Injection Options (htmlInjection)

Environment Variables Options (envVariables)

Example

const configurationOptions = {
  appName: "MyApp",
  baseDir: "/",
  configFile: {
    generate: true,
    fileName: "_app.config.js",
    outputDir: "dist",
  },
  htmlInjection: {
    enable: true,
    templates: ["index.html"],
    position: "head-prepend",
  },
  envVariables: {
    prefix: "VITE_GLOB_",
    files: [".env.production", ".env"],
  },
};

Example

kirklin/celeris-admin

License

MIT License © 2022-PRESENT Kirk Lin