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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With