encrypt-webpack-loader
v1.1.0
Published
A webpack loader and vite plugin to encrypt your apis to keep safe
Downloads
2
Maintainers
Readme
Encrypt-webpack-loader
A webpack loader and vite plugin to decrypt your apis to keep safe.
Install
npm install encrypt-webpack-loader --save-dev
Usage
encrypt
// webpack.config.js
module.exports = {
//...
module: {
rules: [
{
test: /\.ts(x?)$/,
include: path.resolve(__dirname, 'src/apis/'),
use: [
{
loader: 'encrypt-webpack-loader',
options: {
secretKey: 'Your-secret-key',
},
},
],
},
}
}
// vite.config.js
const { CryptoVitePlugin } = require('encrypt-webpack-loader')
// 插件处配置
plugins: [
CryptoVitePlugin({
include: [resolveDir('src/apis/')],
secretKey: 'Your-secret-key',
}),
],
decrypt
// 以axios为例 省略部分代码
import { AES , enc } from 'crypto-js'
this.httpInstance.interceptors.request.use((config) => {
const secretKey = 'Your-secret-key'
if (config.url) {
if (!config.url.startsWith('/')) {
const decrypted = AES(config.url, secretKey).toString(
enc.Utf8,
)
config.url = decrypted || config.url
}
}
return config
})