123456789101112131415161718192021222324252627282930 |
- import webpackSources from 'webpack-sources';
- import { encrypt } from './crypt.js';
- const { RawSource } = webpackSources;
- export const RICOCHET_FILE = process.env.RICOCHET_FILE || 'ricochet.json';
- class EncryptPlugin {
- constructor({ algorithm = 'aes-256-cbc', key }) {
- this.algorithm = algorithm;
- this.key = key;
- }
- apply(compiler) {
- compiler.hooks.compilation.tap('EncryptPlugin', (compilation) => {
- compilation.hooks.afterProcessAssets.tap('EncryptPlugin', () => {
- console.log(`Encrypt ${RICOCHET_FILE} content.`);
- compilation.updateAsset(RICOCHET_FILE, (rawSource) => {
- return new RawSource(
- JSON.stringify(
- encrypt(rawSource.buffer(), this.key, this.algorithm)
- )
- );
- });
- });
- });
- }
- }
- export default EncryptPlugin;
|