pluginImportMetaEnv
Rspack plugin that defines variables as properties of import.meta.env during compile time.
It's same as EnvironmentPlugin but instead process.env.{key} it defines import.meta.env.{key}.
Usage
rspack.config.js
import { pluginImportMetaEnv } from '@krutoo/utils/rspack';
export default {
plugins: [
// just use plugin function
pluginImportMetaEnv(['APP_NAME', 'RELEASE', 'API_URL']),
],
};
Tip: TypeScript definitions
To provide information for the TypeScript about the variables provided by the plugin, you can add type declarations like this:
src/typings/import-meta.d.ts
interface ImportMetaEnv {
[key: string]: any;
// declare your variable here
NODE_ENV?: string;
APP_NAME?: string;
APP_VERSION?: string;
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}
See more info about module augmentation.