# vite-plugin-global-const

> Define constants for your project to facilitate reuse of your code across multiple products

Latest version **0.0.6** (published 2024-07-18) · Apache License 2.0 license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-global-const
pnpm add vite-plugin-global-const
yarn add vite-plugin-global-const
bun add vite-plugin-global-const
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2024-07-18 |
| First published | 2023-05-25 |
| Weekly downloads | 0 |
| License | Apache License 2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | 江程训 |
| Maintainers | censujiang_self |
| Keywords | vite, global const, vite-plugin, const, global |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-global-const
- Repository: https://github.com/censujiang/vite-plugin-global-const
- Issues: https://github.com/censujiang/vite-plugin-global-const/issues
- npm.io page: https://npm.io/package/vite-plugin-global-const

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.0.6 (latest) — 2024-07-18
- 0.0.5 — 2023-11-11
- 0.0.4 — 2023-10-30
- 0.0.3 — 2023-07-23
- 0.0.2 — 2023-05-25
- 0.0.1 — 2023-05-25

## README

# vite-plugin-global-const

Define constants for your project to facilitate reuse of your code across multiple products

## INSTALL

```bash
npm i vite-plugin-global-const -D
#or
yarn add vite-plugin-global-const -D
```

## CONFIG

In your `vite.config.js`, you can add your global constants to the plugin options.For example:

```js
// vite.config.js
import { defineConfig } from 'vite'
import { globalConst } from 'vite-plugin-global-const'

export default defineConfig({
  plugins: [
    globalConst({
      // Global constants for your needs
      MAIN: true
    }),
  ],
})

```

## USAGE

You can use the global constants in your code, they are injected into the `import.meta.env` object.For example:

```js
// content.js
const main = import.meta.env.MAIN
console.log(main)
```

and you will get the following results in the browser console or terminal:

```console
true
```

## For Development Other Plugins

If you are developing a plugin, you can use the global constants in your plugin code, they are injected into the `import.meta.env` object.For example:

```js
import { defineConstCore } from 'vite-plugin-global-const'

export function customPlugin() {
  return {
    name: 'vite-plugin-custom',
    config: () => {
      const defineConst = defineConstCore({
        YourConst: true
      })
      return {
        define: {
          ...defineConst
        }
      }
    }
  }
}
```

## LAST

If you have any questions, please submit an issue, thank you for your support, and if you like this plugin, please give me a star, thank you!

---
_Source: https://npm.io/package/vite-plugin-global-const · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
