我正在尝试通过
@now-node
. 任务基本上是部署一个具有依赖关系的 Polka 服务器,并静态地提供 static/ 和 client/ 文件。我已设法通过 includeFiles 包含 Lambda 所需的文件,但现在我在日志中看到构建器忽略了 package.json 中描述的依赖项。确切的信息是
Starting server on port 3000
Cannot find module 'sirv'
Did you forget to add it to "dependencies" in `package.json`?
但是我在构建日志中看到没有收集依赖项。两者package.json
和package-lock.json
都存在于源文件中。
我将不胜感激有关如何解决此问题的任何建议。
我到达的 now.json 配置如下所示:
{
"version": 2,
"name": "experimental-sapper",
"builds": [
{
"src": "__sapper__/build/index.js",
"use": "@now/node",
"config": {
"includeFiles": [
"../build/**",
"../../static/**"
]
}
},
{
"src": "static/**",
"use": "@now/static"
},
{
"src": "__sapper__/build/client/**",
"use": "@now/static"
}
],
"routes": [
{ "src": "/(.*(\\.css)|(\\.json)|(\\.png))", "dest": "/static/$1" },
{ "src": "/client/(.*)", "dest": "/__sapper__/build/client/$1" },
{ "src": "/(.*)", "dest": "/__sapper__/build/index.js" }
],
"alias": "..."
}
src/server.js 看起来像这样(在汇总捆绑之前):
import sirv from 'sirv';
import polka from 'polka';
import compression from 'compression';
import * as sapper from '@sapper/server';
const { PORT, NODE_ENV } = process.env;
const dev = NODE_ENV === 'development';
const app = polka() // You can also use Express
.use(compression({ threshold: 0 }));
if (dev) {
app.use(sirv('static', { dev }));
}
app.use(sapper.middleware())
.listen(PORT, err => {
if (err) console.log('error', err);
});
export default app.handler;
然后 package.json 也很标准:
"description": "TODO",
"version": "0.0.1",
"scripts": {
"dev": "sapper dev",
"build": "sapper build --legacy",
"export": "sapper export --legacy",
"start": "node __sapper__/build",
"cy:run": "cypress run",
"cy:open": "cypress open",
"test": "run-p --race dev cy:run"
},
"dependencies": {
"compression": "^1.7.1",
"express": "^4.17.1",
"polka": "^0.5.0",
"postcss-define-property": "^0.5.0",
"sirv": "^0.4.0"
},
"devDependencies": {
...
},
"browserslist": "last 2 versions"
}
提前致谢!