Javascript 配置“@babel/runtime-corejs3”以排除es.date.now
我试图阻止Javascript 配置“@babel/runtime-corejs3”以排除es.date.now,javascript,babeljs,sinon,core-js,Javascript,Babeljs,Sinon,Core Js,我试图阻止@babel/preset env+@babel/plugin transform runtime+@babel/runtime-corejs3替换Date.now(),以解决此问题 根据,应该有一种方法防止它应用es.date.nowpolyfill,但我不知道如何应用此配置 例子 index.js 巴别塔透明胶片 注意传输输出的最后一行-我希望它是console.log(Date.now()) 查看了@babel/preset env的文档后,我觉得这就是我要找的,但我无法让它工作
@babel/preset env
+@babel/plugin transform runtime
+@babel/runtime-corejs3
替换Date.now()
,以解决此问题
根据,应该有一种方法防止它应用es.date.now
polyfill,但我不知道如何应用此配置
例子
index.js
巴别塔透明胶片
注意传输输出的最后一行-我希望它是console.log(Date.now())代码>
查看了@babel/preset env
的文档后,我觉得这就是我要找的,但我无法让它工作:
module.exports={
预设:[
['@babel/preset env',{exclude:['es.date.now']}]
],
插件:[
['@babel/plugin转换运行时',{corejs:3}]
]
}
上面给出了一个错误:
> $(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")
...
如何配置Babel在传输过程中排除es.date.now
polyfill
项目文件
package.json
babel.config.js
module.exports={
预设:['@babel/preset env'],
插件:[
['@babel/plugin转换运行时',{corejs:3}]
]
}
请参阅。插件转换运行时不支持浏览器目标。插件转换运行时和预设环境可以独立工作
总而言之。目前它不受支持。下面是准备好签出的代码:当然,你可以通过混淆愚蠢的find-replace算法来绕过这个问题:``+const-dateObj=Date;+log(newdate().getTime())-console.log(Date.now())+log(dateObj.now())```我面临着同样的问题,并且发现如果不使用插件转换运行时,那么它就可以工作。似乎是运行时插件的错误
$(npm bin)/babel index.js
...
console.log(new Date().getTime());
console.log((0, _now["default"])());
> $(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")
...
{
"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"
}
}