我有一个项目,该项目设置为nx-workspace,其中包括一个称为sync的NestJS项目。我试图在Lambda上使用此功能并具有多个功能,但要在NX Workspace外部进行工作,后者会编译完整目录,但是在NX Workspace中它将编译为main.js文件,其中不包含两个Lambda调用NestJS框架的文件。
我认为问题出在这里:
"sync": {
"root": "apps/sync",
"sourceRoot": "apps/sync/src",
"projectType": "application",
"prefix": "sync",
"schematics": {},
"architect": {
"build": {
"builder": "@nrwl/node:build",
"options": {
"outputPath": "dist/apps/sync",
"main": "apps/sync/src/main.ts",
"tsConfig": "apps/sync/tsconfig.app.json",
"assets": ["apps/sync/src/assets"],
"scripts": ["apps/sync/src/app/lambdas/**/*"]
},
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/sync/src/environments/environment.ts",
"with": "apps/sync/src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"builder": "@nrwl/node:execute",
"options": {
"buildTarget": "sync:build"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"apps/sync/tsconfig.app.json",
"apps/sync/tsconfig.spec.json"
],
"exclude": ["**/node_modules/**", "!apps/sync/**/*"]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "apps/sync/jest.config.js",
"tsConfig": "apps/sync/tsconfig.spec.json",
"passWithNoTests": true
}
}
}
总是根据该文件编译JS文件:
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app/app.module';
declare const module: any;
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
logger: ['log', 'error', 'warn', 'debug', 'verbose'],
});
const port = process.env.PORT || 3010;
await app.listen(port, () => {
Logger.log('Listening at http://localhost:' + port);
});
if (module.hot) {
module.hot.accept();
module.hot.dispose(() => app.close());
}
}
bootstrap();
但是,在运行每个功能时,我需要包含两个文件:
import { Handler } from 'aws-lambda';
import { NestFactory } from '@nestjs/core';
import { AppModule } from '../app.module';
import { FooController } from '../foo/foo.controller';
async function bootstrap() {
const app = await NestFactory.createApplicationContext(AppModule);
return app;
}
export const syncFooHandler: Handler = async (event) => {
const app = await bootstrap();
const fooService = app.get(FooController);
return await fooService.sync(event);
};
import { Handler } from 'aws-lambda';
import { NestFactory } from '@nestjs/core';
import { AppModule } from '../app.module';
import { BarController } from '../bar/bar.controller';
async function bootstrap() {
const app = await NestFactory.createApplicationContext(AppModule);
return app;
}
export const syncStudentsHandler: Handler = async (event) => {
const app = await bootstrap();
const barService = app.get(BarController);
return await barService.sync(event);
};
但是这些文件不包含在已编译的main.js
文件中。