-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b24f9b
commit 9f38d73
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,50 @@ | ||
# 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) | ||
``` | ||
|
||
```console | ||
# browser console/terminal | ||
true | ||
``` | ||
|
||
## 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! |