在Babel Require Hook选项中指定--no-highlight-code

时间:2015-06-19 13:02:34

标签: babeljs

如何在Babel的Require Hook选项对象中指定--no-highlight-code选项?

require('babel/register')({
    '--no-highlight-code': true,
    'no-highlight-code': true,
    'noHighlightCode': true,
});
require('./script');

所有这些都会给出错误Unknown option: no-highlight-code

这是Babel命令行使用的一个选项,所以我甚至不确定我是否应该这样使用它,尽管可以使用示例页面列表blacklistwhitelist

babel --help

  Usage: index [options] <files ...>

  Options:

    -h, --help                           output usage information
    -f, --filename [string]              filename to use when reading from stdin - this will be used in source-maps, errors etc
    --module-id [string]                 specify a custom name for module ids
    --retain-lines                       retain line numbers - will result in really ugly code
    --no-non-standard                    enable/disable support for JSX and Flow (on by default)
    --experimental                       allow use of experimental transformers
    --no-highlight-code                  enable/disable ANSI syntax highlighting of code frames (on by default)
    -e, --stage [number]                 ECMAScript proposal stage version to allow [0-4]

1 个答案:

答案 0 :(得分:1)

禁用突出显示代码的选项(默认情况下)为on,命令行选项的(添加)前缀为“no”。

require("babel/register")({ highlightCode: false })是在将对象传递给SyntaxError时在分析时间babel/register中禁用突出显示代码的方法。

传递{ highlightCode: true }什么都不做;默认值为true