encrypt-webpack-loader

1.1.0 • Public • Published

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
})

Package Sidebar

Install

npm i encrypt-webpack-loader

Weekly Downloads

6

Version

1.1.0

License

ISC

Unpacked Size

3.02 kB

Total Files

3

Last publish

Collaborators

  • vipres