Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/censujiang/vite-plugin-global-const
Define constants for your project to facilitate reuse of your code across multiple products
https://github.com/censujiang/vite-plugin-global-const
constraints global global-const vite vite-plugin
Last synced: 12 days ago
JSON representation
Define constants for your project to facilitate reuse of your code across multiple products
- Host: GitHub
- URL: https://github.com/censujiang/vite-plugin-global-const
- Owner: censujiang
- License: apache-2.0
- Created: 2023-05-25T07:25:41.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-07-18T12:39:37.000Z (5 months ago)
- Last Synced: 2024-11-03T06:25:39.466Z (about 1 month ago)
- Topics: constraints, global, global-const, vite, vite-plugin
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/vite-plugin-global-const
- Size: 57.6 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- fucking-awesome-vite - vite-plugin-global-const - Define constants for reuse of your code. (Plugins / Framework-agnostic Plugins)
- awesome-vite - vite-plugin-global-const - Define constants for reuse of your code. (Plugins / Framework-agnostic Plugins)
- jimsghstars - censujiang/vite-plugin-global-const - Define constants for your project to facilitate reuse of your code across multiple products (TypeScript)
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!