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

基于 Egg 封装的框架无法加载 #26

Open
luobogor opened this issue Nov 3, 2022 · 0 comments
Open

基于 Egg 封装的框架无法加载 #26

luobogor opened this issue Nov 3, 2022 · 0 comments

Comments

@luobogor
Copy link

luobogor commented Nov 3, 2022

egg 的 scf_bootstrap 是这么写的

const { Application } = require('egg');

// 如果通过层部署 node_modules 就需要修改 eggPath
Object.defineProperty(Application.prototype, Symbol.for('egg#eggPath'), {
  value: '/opt',
});

const app = new Application({
  mode: 'single',
  env: 'prod',
});

// ...

如果使用基于 Egg 封装的框架,无法加载上层框架,需要做这样的改动才能加载:

// package.json
"egg": {
  "framework": "my-framework"
},
// sls.js
const { Application } = require('my-framework');

Object.defineProperty(Application.prototype, Symbol.for('egg#eggPath'), {
  value: '/opt/node_modules/my-framework',
});

const app = new Application({
  mode: 'single',
  env: 'prod',
});

// ...
# serverless.yml
# 将 component: egg 改成 component: koa
component: koa

inputs:
  entryFile: sls.js

# ......
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant