How to pre-compile Deno script? - deno

Executing deno run script.ts first time is slow, and the second time is faster.
Is there some pre-compile command, to compile and cache scripts, but don't run it?

You can fetch and compile modules into your local cache using deno cache script.ts.
You can also use deno cache --reload script.ts to invalidate the cache and then refetch and recompile.
Reference: Reloading modules | Manual | Deno

You can compile a Deno script into a standalone binary using deno compile.
deno compile https://deno.land/std/examples/welcome.ts
./welcome # Run executable

Related

Imported deno thirdparties in production

Deno does not use any package manager like npm, it only imports the thirdparty dependencies with a URL. Lets see an example below:
import { Application } from "https://deno.land/x/abc#v1.0.0-rc8/mod.ts";
Does the deployed code in production contain the content of https://deno.land/x/abc#v1.0.0-rc8/mod.ts or the server in production has to send a request to the URL to get the thirdparty code?
For production, deno recommends saving your dependencies to git, if you follow that recommendation, then your server won't need to download anything since it will already be cached.
In order to do that you have to set the environment variable DENO_DIR to specify where do you want to download dependencies.
DENO_DIR=$PWD/vendor deno cache server.ts
# DENO_DIR=$PWD/vendor deno run server.ts
With the above command, all dependencies for server.ts will be downloaded into your project, inside vendor/ directory, which you can commit to git.
Then on the production server, you'll have to set DENO_DIR to read from vendor/ and not for the default path, which can be obtained by issuing:
deno info
If you don't store the dependencies on your version control system, then deno will download the dependencies once, and store them into DENO_DIR directory.
Taken from deno manual:
But what if the host of the URL goes down? The source won't be available.
This, like the above, is a problem faced by any remote dependency
system. Relying on external servers is convenient for development but
brittle in production. Production software should always vendor its
dependencies. In Node this is done by checking node_modules into
source control. In Deno this is done by pointing $DENO_DIR to some
project-local directory at runtime, and similarly checking that into
source control:
# Download the dependencies.
DENO_DIR=./deno_dir deno cache src/deps.ts
# Make sure the variable is set for any command which invokes the cache.
DENO_DIR=./deno_dir deno test src
# Check the directory into source control.
git add -u deno_dir
git commit

Migrate from activator 0.13.x to sbt 1.x

I am migrating from activator from 0.13.x to sbt 1.x.
I used to compile my modules like this $ activator clean compile publish-local -Dversion=1
Now, I am trying to do it with sbt since activator has been deprecated, but I can not find how I should migrate to something similar like $ sbt clean compile publish-local -Dversion=1?
Activator (the CLI part) was just a wrapper around sbt with some custom commands. So what you wrote should work the same, expect that the snake-case was deprecated in favor of the camelCase:
sbt clean compile publishLocal
If you need to pass a var to the Java runtime with -D you have to place it before any commands: sbt -Dversion=1 ....
Notice that you use batch mode to run the commands:
Running in batch mode requires JVM spinup and JIT each time, so your build will run much slower. For day-to-day coding, we recommend using the sbt shell or Continuous build and test feature described below.
To follow this recommendation, just run sbt and then enter those commands one by one. Or to run them all sequentially, enter ; clean; compile; publishLocal.

grunt in watch mode and node.js lite-server

Is there a way to start node.js's lite-server from grunt?
I have grunt in watch mode and to use both at the same time I need to open two command prompt (windows). I'd prefer to start both with one grunt command - if possible.
The plugin grunt-exec does the trick with the command npm run lite (depending on package.json configuration).

Why does grunt allow global installations?

I've installed both the grunt-cli and grunt globally using the -g option.
However when I try and run grunt I get this error:
grunt --gruntfile /Users/a/root/config/Gruntfile.js
grunt-cli: The grunt command line interface. (v0.1.13)
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:
http://gruntjs.com/getting-started
This is confusing as it seems to say that you are suppose to do a local install.
It seems contradictory actually. I clearly have a grunt file in place.
Grunt-cli is installed globally so that the grunt command is available to be run from any location on your system. Without the global installation, you would need to rely on somewhat abstract methods of running local grunt installs (npm run-script and friends), which are clunky for this use.
The entire point of the global install is only to load and run a local Gruntfile.js using the locally installed version of Grunt. The error message indicates this:
either a Gruntfile wasn't found or grunt hasn't been installed locally to your project.
In other words, to run Grunt, you need to create a Gruntfile.js and you must have a local copy of Grunt installed to your project alongside the file. The CLI is just there to kick off the process without troublesome fiddling.

Running 'grunt' command on mean.js app just stalling

I am following the installation guidelines as described on mean.js.org Everything seemed to install fine. I have all prereqs installed. I ran npm install after cloning the github repo and then tried to run grunt and I didnt get any errors however It seems to just be stalling on the command line. Last message on the command line is the "debugger is running on port 5858" and then it just sits there.
After some time the message [nodemon] watching 51,839 files - this might cause high cpu usage. To reduce use "--watch" comes up. I am on windows 10 and have all the latest versions of node,npm,grunt and mean.js. I am running the command line as admin.
Mean.js should be running on localhost:3000 but it is not.
This is intended.
There is an application invoked by the grunt command and running in background, watching your files for changes. In default configuration: nodemon and grunt-watch.
This will execute specific tasks based on the files you edited, such as linting JS files or compiling LESS files.
The cmd will probably show something when you edit files in the projects directory.

Resources