Jonathan Newton

Deploying Dojo 2 with Now

Dojo 2 is the next evolution of Dojo. With this brings new tools and even a new language.

This is a quick start guide for deploying your Dojo 2 project with Now.

Now

I have talked about Now in the past with Python deployments. I am a big fan of minimal configuration, the faster I can deploy, the faster I can prove the concept and get to market.

Deploying static files with Now is the fastest and it requires 0 configuration, truly impressive!

Getting Started

Firstly install Now CLI:

1
npm install -g now

Then type now, this will ask you to authenticate. Once that’s done we are ready to go with Now.

Dojo 2

One of the biggest changes to Dojo is Typescript. When I spoke to Dylan Schiemann at Fullstack in London, he said Typescript was central to this cut down, modular evolution of Dojo. In this post we won’t get too deep into Dojo 2 (I will do that at a later date). Dojo 2 is packed full of features that we would expect from modern SPA applications with a massive amount of flexibility with theming and widgets.

For this post we will be using the default project that the CLI generates for us.

1
npm i @dojo/cli -g

Then we create a new boilerplate project called now-test.

1
dojo create app --name now-test

This will create our default project.

Initially, Dojo won’t give us scripts to run or build our project, so we need to add this to our package.json.

1
2
3
"scripts": {
"start": "dojo build --mode dev --watch memory --serve"
},

Run npm start, this will build the project and watch for changes. We can now jump into localhost:9999, there we should see our project.

Exciting stuff!

Deploying Dojo 2 with Now

First we need to create our production build. To do this we need a new command.

1
"build": "dojo build --mode dist"

Running our build command with npm run build will create a new folder called output, this contains 2 folders. The one we are interested in is the dist folder, the other folder contains a standalone bundling performance project.

1
"now-publish": "npm run build && now ./output/dist"

This is our deploy command, it is broken into 2 commands. Firstly we create our build to publish, then we tell Now where our output folder is. Behind the scenes Now will decide how to publish our build folder, since it has an index.html it will treat it as a static folder.

Our complete set of commands should look like this:

1
2
3
4
5
"scripts": {
"start": "dojo build --mode dev --watch memory --serve",
"build": "dojo build --mode dist",
"now-publish": "npm run build && now ./output/dist"
}

Now run npm run now-publish.

Now we can navigate to our output link.