我正在为 npm 构建一个模块,它使用 @types/crypto-js 作为依赖项。我正在用打字稿构建这个模块,问题是当我将代码编译到 dist 文件夹时,它只包含 index.js 文件,不编译 crypto-js 模块,当我运行了一个测试,它说找不到模块 crypto-js。有答案吗?
这是我的 tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es2017", "es7", "es6", "dom"],
"declaration": true,
"outDir": "dist",
"strict": true,
"esModuleInterop": true
},
"include": [
"node_modules/@types/crypto-js"
]
}
答案 0 :(得分:0)
@types/*
包仅提供类型声明。它们总是在纯 JavaScript 中编译为空。您还需要依赖于提供实际功能的 crypto-js
包本身。
根据您的描述,我不确定您是否正在构建要在 NPM 上分发的包。如果是,您根本不需要将 crypto-js
捆绑到您的包中(并且可能不应该);仅仅列出依赖就足够了。安装您的软件包的任何人也将自动获得 crypto-js
。