Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/memory config #44

Merged
merged 6 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
node_modules
examples/*/*
!examples/*/install.js
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ You must make 3 changes to your project to get started:
2. Export the server instance in `src/server.js`
3. Ignore the local build folder `__sapper__`

Check out this [demo project](https://github.com/beyonk-adventures/now-sapper-demo) that uses this builder. It can be used as a template, or a way to verify correct usage of the following instructions.
To install a working example of a vercel-sapper template ready for deployment or development, see the `examples` directory.

```
cd examples/sapper-template
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the first step npx degit ...vercel-sapper or git clone ... or how do you see this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could probably include a git clone step before this. I'm not sure degit is required since the template does its own degit, and there isn't really any need to remove git control from the parent project.

node install.js
```

##### 1. Configure `vercel-sapper` as builder in `vercel.json`

Expand Down Expand Up @@ -66,6 +71,27 @@ Example `package.json`
}
```

##### Memory Configuration

You can change the amount of memory your lambda runs with. This is useful to optimise costs.

Note that reducing memory also reduces the amount of CPU available to the lambda, so try some values before you optimise too much.

```json
{
"version": 2,
"builds": [
{
"src": "package.json",
"use": "vercel-sapper",
"config": {
"memory": 3008 // default, in megabytes
antony marked this conversation as resolved.
Show resolved Hide resolved
}
}
]
}
```

##### No-build usage

Useful if you are building the project on CI, and then want to just push the compiled source.
Expand Down
5 changes: 5 additions & 0 deletions examples/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Installing Examples

Go into the directory for the example you want to see, and run:

`js ./install.js`
antony marked this conversation as resolved.
Show resolved Hide resolved
56 changes: 56 additions & 0 deletions examples/sapper-template/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict'

const replace = require('replace')
const degit = require('degit')
const { writeFileSync, writeFile } = require('fs')
const { join } = require('path')

async function clone () {
const emitter = degit('sveltejs/sapper-template', {
force: true
})

emitter.on('info', info => {
console.log(info.message)
})

return emitter.clone('.')
}

async function patch () {
replace({
regex: /polka\(\)/,
replacement: 'export default polka()',
thgh marked this conversation as resolved.
Show resolved Hide resolved
paths: [
join(__dirname, 'src', 'server.js')
]
})

writeFileSync(
join(__dirname, 'vercel.json'),
`{
"version": 2,
"builds": [
{
"src": "package.json",
"use": "vercel-sapper"
}
]
}`
)

writeFileSync(
join(__dirname, '.vercelignore'),
`__sapper__
cypress
node_modules`
)
}

function info () {
console.log('Example installed. Deploy with `vercel`')
}

clone()
.then(patch)
.then(info)
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ exports.build = async ({

// Use the system-installed version of `node` when running via `vercel dev`
const runtime = meta.isDev ? 'nodejs' : nodeVersion.runtime
const memory = config.memory || undefined

const lambda = await createLambda({
files: {
Expand All @@ -56,7 +57,8 @@ exports.build = async ({
...applicationFiles
},
handler: 'launcher.launcher',
runtime: runtime
runtime,
...memory ? { memory } : {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply memory : config.memory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we defaulting it? I need to check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, this is pretty cool! I have been tinkering how we could make using vercel-sapper easier and this seems like a good start. I'm not sure though if this is easier than manually addng the files and code. I imagine the perfect experience (apart from built-in support) would be to run npx vercel-sapper on an existing sapper project. What do you think?

The reason I don't like this approach is that it requires manual maintenance of dependencies and such as the template is updated. It's the same reason the svelte TS template is a patch rather than yet another unmaintained fork.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What manual maintenance would be required? I think it would run the same install.js but it saves the user from having to clone this repo, running npm install, cd into the examples directory.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who would be responsible for manually merging the original repo into this one every time it is updated?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No manual merging required, check it out! #47

}).catch(e => {
console.error('createLambda.error', e)
console.error('createLambda.config', config)
Expand Down
Loading