CoffeeScript
CoffeeScript is a language that transpiles to JavaScript, which allows you to use a shorter syntax and other features likethe existential operator,shorter array-splicing syntax,block regular expressions and more.
Parcel supports CoffeeScript automatically using the@parcel/transformer-coffeescript
plugin. When a.coffee
file is detected, it will be installed into your project automatically.
CoffeeScript is compiled to JavaScript and processed as described in theJavaScript docs.
Example usage
#<scripttype="module"src="app.coffee"></script>
console.log'Hello world!'
URL dependencies
#In JavaScript files,URL dependencies can be created using theURL
constructor combined withimport.meta.url
. This can be used to reference URLs such as images,workers,service workers, and more.
CoffeeScript does not currently supportimport.meta
. Instead, you can use the CommonJS__filename
variable with thefile:
prefix to convert it to a URL. For example, here's how you could create a worker in CoffeeScript:
newWorkernewURL('worker.js','file:'+ __filename),
type:'module'
The same goes for other types of dependencies like images:
img= document.createElement'img'
img.src=newURL'hero.jpg','file:'+ __filename
document.body.appendChild img