mirror of
https://github.com/koloml/furbooru-tagging-assistant.git
synced 2025-12-23 23:02:58 +00:00
Implemented plugin for swaping defined build-time constants
This commit is contained in:
28
.vite/plugins/swap-defined-variables.js
Normal file
28
.vite/plugins/swap-defined-variables.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @param {SwapDefinedVariablesSettings} settings
|
||||
* @return {import('vite').Plugin}
|
||||
*/
|
||||
export function SwapDefinedVariablesPlugin(settings) {
|
||||
return {
|
||||
name: 'koloml:swap-defined-variables',
|
||||
enforce: 'post',
|
||||
configResolved: (config) => {
|
||||
if (
|
||||
config.define
|
||||
&& process.env.hasOwnProperty(settings.envVariable)
|
||||
&& process.env[settings.envVariable] === settings.expectedValue
|
||||
) {
|
||||
for (const [key, value] of Object.entries(settings.define)) {
|
||||
config.define[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} SwapDefinedVariablesSettings
|
||||
* @property {string} envVariable
|
||||
* @property {string} expectedValue
|
||||
* @property {Record<string, string>} define
|
||||
*/
|
||||
Reference in New Issue
Block a user