配置`@ babel / runtime-corejs3`以排除es.date.now

问题描述 投票:2回答:1

我正试图防止@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是我想要的,但我无法使它正常工作:

the exclude 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 ...

javascript babeljs sinon core-js
1个回答
0
投票

请参见babel.config.js。 plugin-transform-runtime不支持浏览器目标。插件转换运行时和预设环境可以独立工作。

© www.soinside.com 2019 - 2024. All rights reserved.