我正试图防止@babel/preset-env
+@babel/plugin-transform-runtime
+ @babel/runtime-corejs3
替换Date.now()
,以便解决an issue preventing @sinonjs/fake-timers
from working correctly。
根据@sinonjs/fake-timers
,应该有一种方法可以防止它应用documentation for core-js填充,但我不知道如何应用此配置。
es.date.now
index.js
import FakeTimers from '@sinonjs/fake-timers'
FakeTimers.install()
console.log(new Date().getTime())
console.log(Date.now())
注意转移输出的最后一行—我希望它是$(npm bin)/babel index.js
...
console.log(new Date().getTime());
console.log((0, _now["default"])());
查看console.log(Date.now());
的文档后,我觉得@babel/preset-env
是我想要的,但我无法使它正常工作:
theexclude
option上面给我一个错误:
exclude
我如何配置Babel在移植期间排除
module.exports = { presets: [ ['@babel/preset-env', { exclude: ['es.date.now'] }] ], plugins: [ ['@babel/plugin-transform-runtime', { corejs: 3 }] ] }
polyfill?
> $(npm bin)/babel index.js
{ Invariant Violation: [BABEL] ./index.js: Invalid Option: The plugins/built-ins 'es.date.now' passed to the 'exclude' option are not
valid. Please check data/[plugin-features|built-in-features].js in babel-preset-env (While processing: "./node_modules/@babel/preset-env/lib/index.js")
...
es.date.now
package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@babel/register": "^7.9.0"
},
"dependencies": {
"@babel/runtime": "^7.9.2",
"@babel/runtime-corejs3": "^7.9.2",
"@sinonjs/fake-timers": "^6.0.1"
}
}
我正在尝试防止@ babel / preset-env + @ babel / plugin-transform-runtime + @ babel / runtime-corejs3替换Date.now(),以解决防止@ sinonjs / fake的问题-timers from ...
请参见babel.config.js
。 plugin-transform-runtime不支持浏览器目标。插件转换运行时和预设环境可以独立工作。