Skip to content

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

@luobogor

Description

@luobogor

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

# ......

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions