[英]How do I include files for my sever in __sapper__ build in Svelte / Sapper
I am currently attempting to include a server middleware called Parse in my sapper server that is configured in sapper-project/src/server.js
.我目前正在尝试在
sapper-project/src/server.js
中配置的 sapper 服务器中包含一个名为 Parse 的服务器中间件。
express().use('/api', const api = new ParseServer({
databaseURI: 'mongodb://localhost:27017/dev',
cloud: __dirname + '/cloud/main.js',
appId: 'myAppId',
masterKey: 'masterKeyTest', //Add your master key here. Keep it secret!
serverURL: 'http://localhost:3000/api', // Don't forget to change to https if needed
}))
It takes a mandatory property called cloud which takes a path string that imports server script files for cloud functions.它需要一个名为 cloud 的强制性属性,该属性需要一个路径字符串,该字符串为云功能导入服务器脚本文件。 When the sever is built
__dirname
refers to the generated __sapper__
directory.构建服务器时,
__sapper__
__dirname
。 Problem is I do not know how to include /cloud/main.js
in the build result of Sapper.问题是我不知道如何在 Sapper 的构建结果中包含
/cloud/main.js
。
I get this error as wherever I put /cloud/main.js
as its not included in the __sapper__
build file.我得到这个错误,因为我把
/cloud/main.js
因为它不包含在__sapper__
构建文件中。
Error: Cannot find module '/Users/username/Developer/sapper-project/__sapper__/dev/server/cloud/main.js'
Figured it out.弄清楚了。 The rollup plugin copy ("rollup-plugin-copy") copies paths at build time.
汇总插件副本(“rollup-plugin-copy”)在构建时复制路径。 Here is my solution:
这是我的解决方案:
import copy from 'rollup-plugin-copy'
export default {
client: {...}
sever: {
...
plugins: [
copy({
targets: [
{ src: 'src/cloud', dest: '__sapper__/build/server' },
{ src: 'src/cloud', dest: '__sapper__/dev/server' }
]
})
]
}
}
Hopefully it's not a problem when going into production.希望投入生产时不会出现问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.