I am writing services with Serverless Framework & Azure Functions
. Examples out there are very simple. But when I try to take a step further, I run into problem. Currently learning from AWS Lambda
and then trying to implement it on Azure Functions
.
The goal of doing so is:
1) Implement functions as es6
classes and then building the project with webpack.
2) Find a right project structure, which makes more sense.
3) Follow SoC pattern.
I have created a github
project https://github.com/GeekOnGadgets/serverless-azure-settings当我尝试构建此项目serverless package
时,它会创建.serverless
文件夹,其中包含.zip
文件(编译版)。当我运行serverless deploy
时,我理解将其部署到azure。但是当我检查Azure时,该功能只是开发代码而不是编译代码(请参阅下面的代码)。
有人可以帮忙解决这个问题。任何建议表示赞赏。
import Settings from './src/Settings/Settings'
module.exports.settings = (event, context, callback) => {
let settings = new Settings();
const response = {
statusCode: 200,
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(settings.dev()),
};
callback(null, response);
}
答案 0 :(得分:0)
确实javascript azure函数在nodejs上运行,因此commonjs模块是自然格式。节点本身也支持ES6的大部分,但节点的功能版本可能不是最新版本。
但是,在node_modules中加载所有依赖项时存在当前的速度问题。这是由于文件访问,因此存在一种解决方法,将所有内容捆绑到一个脚本中,即package.json - >要点。
我无法评论如何适应无服务器,但这可能有助于澄清。
答案 1 :(得分:0)
据我所知,Node.js仍为模块导入/导出ES6语法not support。另请参阅here。
尝试从
更改新部署import Settings from './src/Settings/Settings'
到
const Settings = require('./src/Settings/Settings')