此插件不适用于包含由object-hash 问题和tscache.ts引起的 async/await 语法的插件。 我认为这很难修复对象哈希,因为现在无法检测异步函数。 那么有没有没有对象哈希的替代方案?
import svgr from '@svgr/rollup';
import typescript from 'rollup-plugin-typescript2';
export default {
...
plugins: [
replace({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) }),
svgr(),
typescript({
useTsconfigDeclarationDir: true,
})
],
...
};
没有相关性。
没有相关性。
[!] (rpt2 plugin) Error: Unknown object type "asyncfunction"
src/components/atoms/Icon/index.ts
Error: Unknown object type "asyncfunction"
at Object._object (/Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:218:17)
at Object._function (/Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:319:14)
at Object.dispatch (/Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:185:30)
at /Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:246:18
at Array.forEach (<anonymous>)
at Object._object (/Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:242:21)
at Object.dispatch (/Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:185:30)
at /Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:260:23
at Array.forEach (<anonymous>)
at Object._array (/Users/vwxyutarooo/Projects/kouzoh/mercari-web-jp-component/node_modules/rollup-plugin-typescript2/node_modules/object-hash/index.js:259:20)
我添加了一个解决方法来忽略对象哈希无法处理的任何内容(请参阅 objecthash 分支, objectHashIgnoreUnknownHack
选项)。 不过,这可能会使缓存过时,因此不是一个好的长期解决方案。
@韦斯伯格
我必须承认我很惊讶到目前为止这还不是一个问题,因为异步函数现在非常普遍😀。 这也是为什么我认为简单地忽略它会导致大量缓存问题的原因。 我前段时间提交给 object-hash 的 PR 就是这个问题的结果,我建议您删除对 object-hash 的依赖。 我非常有信心前段时间提交的 PR 可以正常工作,因为它匹配错误消息中提供的相同值,并通过了两个单元测试并解决了此插件中的问题,因此请随时依赖 PR而不是这里的 NPM 包。
@vwxyutarooo ,一个直接的解决方法是在配置中设置clean: true
以完全绕过缓存。 或者(对不起插件)我构建了https://github.com/wessberg/rollup-plugin-ts也可以正常工作
@wessberg是的,我想没有多少汇总插件在其界面中具有异步功能。
您知道散列对象的更好方法吗? 我需要部分基于启动时传入的汇总配置对象(因此包含所有使用的插件的源)创建缓存键。
顺便说一句,澄清一下 - 该问题适用于汇总配置本身中的异步内容。 被转译的代码中的异步不是问题,因为代码是基于源文本进行散列的。
嗯,好吧,您可以将 sha1 应用于 JSON.stringify 使用自定义替换器对整个配置进行处理的结果,该替换器将插件映射到它们的name
属性,我很确定这是必需的。
例如,以下汇总配置:
{
// ...
treeshake: true,
plugins: [
myPlugin1(),
myPlugin2()
],
// ...
}
可以转换为以下 JSON 表示:
{
"treeshake": true,
"plugins": [
"name-of-my-plugin-1",
"name-of-my-plugin-2"
]
}
然后你可以应用 sha1 并得到一个 base64 字符串或类似的东西你可以用作缓存键?
我正在考虑这些问题,但这不会从缓存的考虑中删除更多的东西吗? 我怀疑object-hash
是专门制作的,因为JSON.stringify
丢弃了任何不是纯值属性、数组或字典的东西——json 规范中没有其他内容。
我想我可以合并package-lock,json
的哈希值和等价的纱线,如果有可靠的方法可以找到它们。 (减轻objectHashIgnoreUnknownHack
选项的影响)
谢谢大家讨论这个问题。 实际上clean: true
选项不会绕过缓存过程,因此它甚至在一段时间内都不起作用。 但是,正如@ezolenko所说, ignoreUnknown
可能是解决此问题的方法。 无论如何我会等待0.16.2!
@vwxyutarooo ,我假设clean: true
使用 noop 缓存策略。 这就是我记得@ezolenko 前段时间实施的内容。 如果它仍然尝试从汇总配置中计算缓存键,则在我看来该行为需要调查
我不知道这对对象哈希结果有何影响,但是objecthash
分支上的objectHashIgnoreUnknownHack
选项对我有用。
我对缓存进行了一些修改,因此clean: true
甚至不会调用对象哈希并将所有内容合并到 master 中。 我会在几天后发布
现在在 0.17.0
对于不使用objectHashIgnoreUnknownHack
hack 的另一种解决方法,我使用rollup-plugin-require-context
遇到了这个问题,以下代码段似乎有效:
import requireContextORIGINAL from 'rollup-plugin-require-context'
const requireContext = (options) => {
const plugin = requireContextORIGINAL(options)
return {
name: plugin.name,
transform(code, id) {
return plugin.transform(code, id)
}
}
}
即,使transform
成为返回承诺的普通函数。
以为我会在这里为人们添加一个更新,这里的根本原因最终在https://github.com/puleos/object-hash/pull/90 (非常类似于 https://github.com/puleos/上面引用的 object-hash/pull/68)和这里在 #203 中。 无需使用objectHashIgnoreUnknownHack
来支持异步插件,也不再有缓存问题 -- 刚刚发布为 v0.26.0 🎉 😄
最有用的评论
我必须承认我很惊讶到目前为止这还不是一个问题,因为异步函数现在非常普遍😀。 这也是为什么我认为简单地忽略它会导致大量缓存问题的原因。 我前段时间提交给 object-hash 的 PR 就是这个问题的结果,我建议您删除对 object-hash 的依赖。 我非常有信心前段时间提交的 PR 可以正常工作,因为它匹配错误消息中提供的相同值,并通过了两个单元测试并解决了此插件中的问题,因此请随时依赖 PR而不是这里的 NPM 包。
@vwxyutarooo ,一个直接的解决方法是在配置中设置
clean: true
以完全绕过缓存。 或者(对不起插件)我构建了https://github.com/wessberg/rollup-plugin-ts也可以正常工作