Giter Club home page Giter Club logo

Comments (6)

CaiWenlie avatar CaiWenlie commented on June 14, 2024 1

commonjsHelpers.js 是 Vite 中生成的一个虚拟文件名,本身就不存在,看有没有办法直接判断一下这个文件名,将它忽略掉

额,打包之后还是有这个文件是咋回事
image

from vite-plugin-dts.

qmhc avatar qmhc commented on June 14, 2024

Would you provide a test project to reproduce this issue?

from vite-plugin-dts.

skimhugo avatar skimhugo commented on June 14, 2024

`import { encrypt, decrypt } from 'crypto-js/aes';
import UTF8, { parse } from 'crypto-js/enc-utf8';
import pkcs7 from 'crypto-js/pad-pkcs7';
import ECB from 'crypto-js/mode-ecb';
import md5 from 'crypto-js/md5';
// import UTF8 from 'crypto-js/enc-utf8';
import Base64 from 'crypto-js/enc-base64';
import type WordArray from 'crypto-js/lib-typedarrays';
import type crypto from 'crypto-js';
type CipherParams = crypto.lib.CipherParams;

// type WordArray = lib.WordArray;
// aes encryption key
export const cacheCipher = {
key: '11111000001111@',
iv: '@11111000001111
',
};

// 加密参数
export interface EncryptionParams {
key: string;
iv: string;
}

interface Format {
stringify: (cipherParams: CipherParams) => string;
parse: (str: string) => CipherParams;
}

interface CipherOption {
iv?: WordArray | undefined;
format?: Format | undefined;
[key: string]: any;
}
// interface CipherOptionCopy {
// /**
// * The IV to use for this operation.
// */
// iv?: WordArray | undefined;
// format?: Format | undefined;
// [key: string]: any;
// }

// export interface CipherOptions {
// mode: typeof ECB;
// padding: typeof pkcs7;
// key: WordArray | null;
// iv: WordArray | null;
// }

// JSON.stringify()
// JSON.parse()
// usage const encryption = new AesEncryption({ key, iv });
// const stringifyValue = this.hasEncrypt
// ? this.encryption.encryptByAES(stringData)
// : stringData;
// const decVal = this.hasEncrypt ? this.encryption.decryptByAES(val) : val;
// const data = JSON.parse(decVal);
//

// aes加密器
export class AesEncryption {
private readonly key: WordArray | undefined = undefined;
private readonly iv: WordArray | undefined = undefined;

public constructor(opt: Partial = {}) {
const { key, iv } = opt;
if (!key || !iv) {
throw new Error('the key or iv can not be empty!');
} else if ([key.length, iv.length].some((item) => item !== 16)) {
throw new Error('the key or iv must be 16 bits!');
}
if (key) {
this.key = parse(key);
}
if (iv) {
this.iv = parse(iv);
}
}

public get getOptions(): CipherOption {
return {
mode: ECB,
padding: pkcs7,
key: this.key,
iv: this.iv,
};
}

// 加密
public encryptByAES(cipherText: string) {
return encrypt(cipherText, this.key as WordArray, this.getOptions).toString();
}

// 解密
public decryptByAES(cipherText: string) {
return decrypt(cipherText, this.key as WordArray, this.getOptions).toString(UTF8);
}
}

export function encryptByBase64(cipherText: string) {
return UTF8.parse(cipherText).toString(Base64);
}

export function decodeByBase64(cipherText: string) {
return Base64.parse(cipherText).toString(UTF8);
}

export function encryptByMd5(password: string) {
return md5(password).toString();
}
`

index.ts:
export * from '@/cipher';
dependency
"crypto-js": "^4.1.1",

from vite-plugin-dts.

skimhugo avatar skimhugo commented on June 14, 2024

@qmhc I think this problem is because crypto-js is a umd package.
I'm trying rewrite crypto-js to ts project.
but I think if there are common solution is good

from vite-plugin-dts.

luozhihua avatar luozhihua commented on June 14, 2024

commonjsHelpers.js 是 Vite 中生成的一个虚拟文件名,本身就不存在,看有没有办法直接判断一下这个文件名,将它忽略掉

from vite-plugin-dts.

skimhugo avatar skimhugo commented on June 14, 2024

@luozhihua 没有继续深挖这个问题,目前用 tsup 和 tsc 进行 type 的打包。由于 type 实际只存在于运行态,目前我计划后续研究下 esbuild 在这方面的问题。依赖 rollup 进行对 ts 的类型打包有一些问题,尤其因为我还用了 pnpm,尤其麻烦。只好先作罢了。

from vite-plugin-dts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.