Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile time file read in CoffeeScript

I want to write coffeescript that would read a file at compile time and produce a javascript file that initializes a variable with the file contents.

My app has a bunch of error messages and stubs that need to be maintained independently by copy editors and such. But all of them need to be inline in the js that is served to the client browser.

Are there 'pre-processor' directives that will let me do this?

like image 949
Karra Avatar asked Nov 01 '22 09:11

Karra


1 Answers

Javasccript in and of itself doesn't have this capability. So what you are trying to do is not a good practice. The variables that you are trying to change on compile time, keep them in a separate javascript file. Then while building your project, initialize those variables in the separate file and concat them to serve (possibly minified) javascript file. There are tools available to do this. Check out uglify and grunt

like image 160
Juzer Ali Avatar answered Nov 09 '22 07:11

Juzer Ali