@codegeekdevs/vite-encrypt-file
v1.0.2
Published
A Vite plugin that automatically encrypts and decrypts chosen files during development and build processes.
Maintainers
Readme
@codegeekdevs/vite-encrypt-file
A Vite plugin that automatically encrypts and decrypts chosen files during development and build processes.
Features
- Automatic Encryption/Decryption: Process files on build start based on configured actions
- File Watching: Automatically encrypt files when they change during development
- Flexible Configuration: Support for multiple files with different encryption needs
- Security: Protect sensitive configuration files and environment data
Installation
npm install @codegeekdevs/vite-encrypt-fileUsage
Add the plugin to your vite.config.js:
import { defineConfig } from 'vite';
import encrypt from '@codegeekdevs/vite-encrypt-file';
export default defineConfig({
plugins: [
encrypt({
password: 'your-encryption-password',
create: [
{ action: 'decrypt', src: '.env.encrypted', dest: '.env' },
{ action: 'encrypt', src: '.env', dest: '.env.encrypted' }
],
watch: [
{ src: '.env', dest: '.env.encrypted' }
]
})
]
});Configuration
Options
password(required): The encryption/decryption passwordcreate(optional): Array of actions to perform on build startwatch(optional): Array of files to watch and encrypt when changed
Create Actions
Each item in the create array should have:
action: Either'encrypt'or'decrypt'src: Source file pathdest: Destination file path
The plugin only processes create actions when the source file exists and the destination file doesn't exist.
Watch Configuration
Each item in the watch array should have:
src: Source file path to watchdest: Destination file path for encrypted output
When a watched file changes, it will be automatically encrypted to the destination path.
Example Use Cases
Protecting Environment Files
Decrypt an encrypted .env file on start, and re-encrypt it when changes are made:
encrypt({
password: 'my-secret-key',
create: [
{
action: 'decrypt',
src: '.env.encrypted',
dest: '.env'
}
],
watch: [
{
src: '.env',
dest: '.env.encrypted'
}
]
})Encrypting Configuration Files
Encrypt sensitive configuration files during development:
encrypt({
password: 'my-secret-key',
watch: [
{
src: 'config/secrets.json',
dest: 'config/secrets.json.encrypted'
}
]
})Security Considerations
- Keep your encryption password secure and never commit it to version control
- Use environment variables for passwords in production
- Add decrypted files to
.gitignoreto prevent accidental commits - Store only encrypted versions of sensitive files in your repository
License
MIT
Author
David Faltermier [email protected]
Repository
https://gitlab.com/codegeekdev/node-package-vite-encrypt-file
Issues
https://gitlab.com/codegeekdev/node-package-vite-encrypt-file/issues
