How do I use babel in a node CLI program?

前端 未结 1 1825
遇见更好的自我
遇见更好的自我 2021-01-28 09:07

I\'m writing a small CLI tool in node and would like to use ES6 for that.

index.js looks like:

#!/usr/bin/env node

require(\'babel/register\');
module.e         


        
1条回答
  •  [愿得一人]
    2021-01-28 09:37

    The require hook is meant more for local development than for production use. Ideally you'd precompile before distributing your package. You are running into https://github.com/babel/babel/issues/1889.

    You'll need to explicitly tell the register hook not to ignore your application.

    require('babel/register')({
      ignore: /node_modules\/(?!my-tool)/
    });
    

    0 讨论(0)
提交回复
热议问题