How can I compile individual CoffeeScript files in the assets directory?

我与影子孤独终老i 提交于 2020-01-05 04:59:49

问题


I have an application built in Brunch.io that builds the main framework into app.js, but in my assets folder I have various small coffeescript scripts that need to be compiled individually, and not merged together into one.

Is there a way to compile the CS first and then move it to the public folder like everything else in assets?

I notice that there are some plugins for doing this exact thing with Jade templates (so you can have .jade files in your assets folder). Would this need to be a new plugin?

If there's no obvious way to do it, is there at least a way to define the config file so that it can watch a different folder and compile each .coffee file to it's own .js file, without either joining them all together, or needing to specify each file in the config?


回答1:


Since there are no answers, here's the (slightly hacky) way I ended up doing it:

I installed the After-Brunch plugin and added these two commands to my config file, which get run after every compile by Brunch:

  plugins:
    afterBrunch: [
      'find public/ -type f -name "*.coffee" -delete'
      'coffee --compile --output public app/assets/'
    ]

So this simply explicitly deletes the .coffee files that Brunch moved to public/, and then compiles all the .coffee files in assets/ and moves them to public/. Hacky but it works fine.

This annoyingly feels quite backwards: it would have felt much cleaner (even if only in my head) to compile those .coffee files that were already moved into public/ by Brunch, but Coffee doesn't have an in-place conversion option (i.e. replacing the files) that I know of, and running the converter on the files in public/ first and then deleting all *.coffee files didn't work, because the delete command executed before the compile command was finished... But again, this distinction is probably just in my head -- it's just as efficient doing it this way.

If anyone has a more Brunch-like solution, that would be great.



来源:https://stackoverflow.com/questions/21316338/how-can-i-compile-individual-coffeescript-files-in-the-assets-directory

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