Transpile server files recursively with babel

ε祈祈猫儿з 提交于 2019-12-11 08:42:46

问题


My folder structure is such:

functions
-- dist
-- private
-- server
---- controllers
---- middleware
------- clientAuth.js
------- someOtherAuth.js
---- index.js
---- model.js
---- router.js

I want to transpile all the .js files in my server folder into .dist. At present in my package.json I have

 "scripts": {
    "prepare": "babel ./server/**/*.js --retain-lines -d ./dist"
  },

This only transpiles the files in the subdirectories in server, but not the files in the root of server. What can I use to transpile and place into .dist all the files in the root and the subdirectories?


回答1:


If you are only going to have .js files in your server, you could replace ./server/**/*.js with ./server/

So you would end up with

"scripts": {
  "prepare": "babel ./server/ --retain-lines -d ./dist"
}

in case you still need just the .js extension, there should be an -x flag to archive that

"scripts": {
  "prepare": "babel ./server/ -x '.js'  --retain-lines -d ./dist"
}


来源:https://stackoverflow.com/questions/50601244/transpile-server-files-recursively-with-babel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!