-
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
4bcf77a
commit 945a233
Showing
3 changed files
with
46 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* eslint-env node */ | ||
|
||
import dotenv from 'dotenv'; | ||
import replace from 'replace-in-file'; | ||
|
||
dotenv.config(); // Load environment variables | ||
|
||
const getReplacements = () => { | ||
// Filter only variables starting with VITE_ | ||
const viteEnvVars = Object.keys(process.env).filter(key => key.startsWith('VITE_')); | ||
|
||
// Create replacement options for each VITE_ variable | ||
return viteEnvVars.map(key => ({ | ||
from: new RegExp(`import.meta.env.${key}`, 'g'), | ||
to: JSON.stringify(process.env[key]), | ||
})); | ||
}; | ||
|
||
const options = { | ||
files: 'demo/*.js', // Target all .js files in dist directory | ||
from: [], | ||
to: [], | ||
}; | ||
|
||
// Generate and apply replacements | ||
const replacements = getReplacements(); | ||
replacements.forEach(replacement => { | ||
options.from.push(replacement.from); | ||
options.to.push(replacement.to); | ||
}); | ||
|
||
replace(options) | ||
.then(results => { | ||
console.log(results.filter(r => r.hasChanged).length, 'files changed.') | ||
}) | ||
.catch(error => { | ||
console.error('Error occurred:', error); | ||
}); |
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