
[英]How can I get the value of the title attr of an <a> element and use it somewhere else in the same html page
[英]How can I access a project's babel-related deps from somewhere else?
这是一个奇怪的需求,但我认为这不是X / Y问题。 我需要从我自己的工具访问与项目的babel相关的依赖关系和配置。 我的工具可能是一个devDep,或全球的装机量,或运行npx
; 我没办法知道
我知道可以用babel-register
完成,因为像babel-tape-runner
这样的好工具就可以了。 但是,就我而言,我不能只require('babel-register')
然后需要其他文件。 我在module._compile
使用module._compile
。 (在这种情况下,写一个临时文件,运行它,然后取消链接并不是一个好选择,因为它可能发生数百次或数千次。)
在将这些东西传递给module._compile
之前,有什么方法可以使用用户项目的本地Babel配置,预设和插件来对我从某处读取的某些代码进行module._compile
?
事实证明,正确的答案是不使用babel-register
。 我快速了解了Jest的工作方式,他们直接使用babel-core
。 将babel.transform(code, { extends: babelRc }).code
module._compile
到module._compile
效果很好。 整个差异在这里可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.