In this example we will be deploying an mdx-deck presentation which will also contain:
- Images that we want to be available offline
- Custom MDX-deck layouts
- Code snippets that we want to be available offline
- A custom Codesurfer React component to navigate code snippets
A sample presentation has been created at demo-advanced.mdx
First we need to create a now.json
configuration file to instruct Now how to build the project.
For this example we will be using our newest version Now 2.0.
By adding the version
key to the now.json
file, we can specify which Now Platform version to use.
We also need to define how the project will be built. In this case, we will use the @now/mdx-deck Builder.
Builders are modules that take a deployment's source and return an output, consisting of either static files or dynamic Lambdas.
In this case we are going to use @now/static-build
to build and deploy our static application selecting the package.json
as our entry point. We will also define a name for our project (optional).
If we take a look at our demo presentation demo-advanced.mdx
we will see that we are loading images and code snippets.
As an added bonus, if you look at line forty-three (43) of demo-advanced.mdx
there is a custom React component that allows the presenter to identify and highlight specific lines from the example code snippet:
<CodeSurfer
code={require("!raw-loader!./snippets/example-dockerfile.snippet")}
title="Dockerfile for photo-share-api"
showNumbers
steps={[
{}, // First step should be an overview of the snippet
{lines: [1], notes: "Specify the base Node.js image"},
{range: [6,7], notes: "Create the working directory on our process"},
{range: [9,11], notes: "Copy and install our dependencies just like we would locally"},
{range: [13,14], notes: "Copy our application code over"},
{lines: [15], notes: "What is this? It seems a little...unusual."},
{range: [17,19], notes: "We need to define ports for Docker to access"},
{range: [21,22], notes: "This is the command to start our back-end server"},
{}
]}
/>
// Special thanks to https://elijahmanor.com/code-surfer/ for this custom component
We must update our now.json
file by adding a routes key to handle this. Our default route /
will serve up the index.html
page generated through the mdx-deck build process. We are also adding additional routes /images
and /snippets
for additional assets we are including with the presentation.
{
"version": 2,
"name": "mdx-deck-advanced",
"builds": [
{"src": "package.json", "use": "@now/static-build"}
],
"routes": [
{ "src": "^/images/(.*)", "dest": "/images/$1" },
{ "src": "^/snippets/(.*)", "dest": "/snippets/$1" },
{ "src": "index.html", "dest": "/index.html" }
]
}
Visit our documentation for more information on the now.json
configuration file.
We also need to include a script in package.json
named "now-build"
that specifies what command Now will run on the server to "build" your application.
By default, MDX-deck will output the build to the dist
directory. We also need to explicitly copy folders containing our images and our snippets to the dist
folder.
{
"scripts": {
...
"now-build": "mdx-deck build demo-advanced.mdx --no-html && cp -r images dist/ && cp -r snippets dist/"
}
}
We are now ready to deploy the app.
now
- Copy folder - decks/_empty_deck_template
- Give new name
- Edit package.json of deck
{
"private": true,
"name": "empty-deck-template", // change name
"version": "1.0.0",
"scripts": {
// can stay the same
}
}
Edit root now.json to include build for new deck:
{ "version": 2,
"name": "mdx-deck-advanced",
"builds": [
// ...
{
"src": "decks/your-new-deck/package.json",
"use": "@now/static-build"
}
]
}
// /deck.js
import intro from './intro.mdx'
// ...
import yourNewDeck from './decks/yourNewDeck';
export { default as theme } from './theme'
export default [
...intro,
// ...
...yourNewDeck
]
yarn workspace nameYouGaveInPackage packageServeCommand
yarn run serve
Format
- Will have some talking to concepts/slides
- Slides will cover high level points
- Will be 'talked to' more than read
- Typically followed by live+coding some examples to explore the concept
- Can answer questions people have during this time,
- Can also code examples as part of answering questions
- Other sections will have some exercises / examples setup
- will use various online tools such as
- repl.it
- codesandbox
- stackblitz
- will use various online tools such as
- Will aim for most large sections to have a larger exercise to work with
- Will have initial online enviornment setup
- Some initial code
- Clear instructions / Requirements
- For Days 3 & 4
- Will have basic setup of an application
- Set of features to be built out that will leverage the concepts taught
- Features can have 'stretch goals'
- Allow for basic implementation
- Allow for room for refactoring, or usage of more advanced patterns
- Link to Slides / Material will be provided before hand
- Slides will contain teaching Material
- Links to online tools
- Links to other useful learning / reading resources that cover topics more in depth