This module is used to include source files as Build outputs. You can think of @now/static
as a module that copies over files.
When to Use It
When you deploy a project that has no Builds we serve the sources directly.
For example, when you deploy a single file (now photo.jpg
) or a directory with no now.json
and/or no builds
inside it.
However, if you define a build step, Now will only include its outputs in the resulting deployment, as a security precaution to avoid serving unintended files to the public.
In those circumstances, if you want to include unmodified source files as outputs, you can use @now/static
.
How to Use It
Suppose you have a directory with three files:
function.js
- A Node.js function you want to expose.index.html
- A source file you want to serve without modification.README.md
- A source file you never want to serve.
If your now.json
looks like this:
{ "version": 2, "builds": [{ "src": "function.js", "use": "@now/node" }] }
Then only the build outputs of @now/node
will be included: a lambda.
To see for yourself, check the resulting deployment https://builds-deployment-r33zqy3gu.now.sh
. Also, the source code of the deployment can be checked by appending /_src
e.g. https://builds-deployment-r33zqy3gu.now.sh/_src
.
To also serve index.html
, you'll want to add a @now/static
build:
{ "version": 2, "builds": [ { "src": "function.js", "use": "@now/node" }, { "src": "index.html", "use": "@now/static" } ] }
You can see the resulting deployment in action here: https://builds-deployment-2d7eouze2.now.sh
You can also publish a subfolder of static files and have it appear at the root of the deployment. For example, a static folder called public
might contain several CSS files. Use the following to deploy its contents recursively:
{ "version": 2, "builds": [ { "src": "public/**", "use": "@now/static" } ], "routes": [ { "src": "/(.*)", "dest": "public/$1" } ] }
Without the routes
entry above, the static CSS files would be located at /public/*.css
instead of the expected /*.css
. The route rewrite above uses a regular expression to capture wildcard paths and route them to the matching file inside the public
directory. The Routes documentation has more information on routing configuration.
Technical Details
Entrypoint
You can specify any file or set of files as the src
of a build that uses @now/static
.