Compiling and running your code
Now that you have some Derw code, it's time to turn it into something useful. This can be done through either compiling the code, or through bundling it - which also compiles your code.
Both bundling and compiling have watching support, through the --watch
flag.
The best workflow for Derw currently is to have the generated TypeScript files open for your project, to ensure that the TypeScript part compiles
Compiling
Compiling Derw can be done through the derw compile
command. It will compile everything in your src
folder and anything that they depend upon. You can specify if you want to generate TypeScript or JavaScript, but the recommended option is TypeScript.
Typical usage of derw compile
doesn't use any flags
You can then run the compiled code via ts-node src/<NameOfYourFile>.ts
or node src/<NameOfYourFile>.js
if you used js as an target. Note that if you used js as a target, your dependencies may need to be compiled if they relied on an npm package that did not provide JavaScript output.
Bundling
When you produce JavaScript for a website, you would typically want to bundle all the files into a single file. This is done in Derw through derw bundle
, which uses esbuild underneath. Bundling first compiles the Derw code, then uses esbuild to produce a JavaScript file.
You would then want to reference the generated file inside a html file, for example:
Last updated