# 适用于Vite的全局常量插件 **Repository Path**: censujiang/vite-plugin-global-const ## Basic Information - **Project Name**: 适用于Vite的全局常量插件 - **Description**: 为您的项目定义常量,以促进您的代码在多个产品中的重用 - **Primary Language**: TypeScript - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: https://npmmirror.com/package/vite-plugin-global-const - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2023-05-25 - **Last Updated**: 2023-07-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## 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 ``` ## 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!