Skip to content

Commit

Permalink
refactor(build): use esbuild intead of webpack
Browse files Browse the repository at this point in the history
Replace `webpack` that went slower with `esbuild`. It significantly reduce the build speed (more
than x20 on my quad core!).

BREAKING CHANGE: The compiler were moved up to the `@whook/whook` project since it was the same for
AWS/GCP and could be reused for other kinds of builds. Also existing project will have to remove
`babel-loader`, `webpack` of dev dependencies and add `esbuild` instead.
  • Loading branch information
nfroidure committed Mar 3, 2021
1 parent 17f810e commit bdfcd2f
Show file tree
Hide file tree
Showing 20 changed files with 810 additions and 1,718 deletions.
1,659 changes: 540 additions & 1,119 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions packages/whook-aws-lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ Install this module and its peer dependencies :

```sh
npm i @whook/aws-lambda;
npm i --save-dev @whook/http-transaction babel-loader babel-plugin-knifecycle webpack
npm i --save-dev @whook/http-transaction esbuild
```

Add this module to your Whook plugins and tweak the 2 build functions in your
`build.ts` main file:

```diff
- import YError from 'yerror';
+import {
+ runBuild as runBaseBuild,
+ prepareBuildEnvironment as prepareBaseBuildEnvironment,
Expand Down Expand Up @@ -88,7 +89,7 @@ export async function prepareBuildEnvironment(
+ $ = await prepareBaseBuildEnvironment($);


// The build often need to know were initializer
// The build often need to know were initializers
// can be found to create a static build and
// remove the need to create an injector
$.register(
Expand All @@ -110,9 +111,9 @@ export async function prepareBuildEnvironment(
And add the AWS Lambda config (usually in `src/config/common/config.js`):

```diff
+ import type { WhookCompilerConfig } from '@whook/whook';
+ import type {
+ WhookCompilerConfig,
+ WhookAPIOperationAWSLambdaConfig,
+ WhookAPIOperationGCPFunctionConfig
+ } from '@whook/aws-lambda';

// ...
Expand All @@ -126,8 +127,6 @@ const CONFIG: AppConfigs = {
+ COMPILER_OPTIONS: {
+ externalModules: [],
+ ignoredModules: [],
+ extensions: ['.ts', '.js', '.json'],
+ mainFields: ['browser', 'main'],
+ target: '14',
+ },
};
Expand All @@ -148,6 +147,7 @@ To build your functions :
```sh
# Build all functions
npm run compile && npm run build

# Build only one function
npm run compile && npm run build -- getPing
```
Expand Down
18 changes: 0 additions & 18 deletions packages/whook-aws-lambda/package-lock.json

This file was deleted.

11 changes: 1 addition & 10 deletions packages/whook-aws-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
"url": "https://github.com/nfroidure/whook/issues"
},
"homepage": "https://github.com/nfroidure/whook",
"peerDependencies": {
"babel-loader": "^8.1.0",
"babel-plugin-knifecycle": "^5.0.0",
"webpack": "^5.11.1"
},
"dependencies": {
"@types/aws-lambda": "^8.10.72",
"@types/bytes": "^3.1.0",
Expand All @@ -62,8 +57,6 @@
"common-services": "^9.0.0",
"cpr": "3.0.1",
"knifecycle": "^11.1.0",
"memfs": "3.2.0",
"memory-fs": "0.5.0",
"mkdirp": "^1.0.4",
"openapi-types": "^7.2.3",
"qs": "^6.9.6",
Expand All @@ -87,7 +80,6 @@
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-knifecycle": "^5.0.0",
"eslint": "^7.13.0",
"eslint-plugin-prettier": "^3.1.4",
Expand All @@ -97,8 +89,7 @@
"metapak-nfroidure": "11.0.4",
"prettier": "^2.1.2",
"rimraf": "^3.0.2",
"typescript": "^4.0.5",
"webpack": "^5.11.1"
"typescript": "^4.0.5"
},
"contributors": [],
"engines": {
Expand Down
14 changes: 4 additions & 10 deletions packages/whook-aws-lambda/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ import Knifecycle, {
constant,
initInitializerBuilder,
} from 'knifecycle';
import initCompiler, {
DEFAULT_COMPILER_OPTIONS,
DEFAULT_BUILD_OPTIONS,
} from './services/compiler';
import { DEFAULT_BUILD_OPTIONS, initCompiler } from '@whook/whook';
import initBuildAutoloader from './services/_autoload';
import {
dereferenceOpenAPIOperations,
getOpenAPIOperations,
} from '@whook/http-router';
import type { Autoloader, Dependencies, BuildInitializer } from 'knifecycle';
import type {
WhookOperation,
WhookCompilerOptions,
WhookCompilerService,
WhookCompilerConfig,
} from './services/compiler';
import type { Autoloader, Dependencies, BuildInitializer } from 'knifecycle';
import type { WhookOperation } from '@whook/whook';
} from '@whook/whook';
import type { OpenAPIV3 } from 'openapi-types';
import type { LogService } from 'common-services';
import type { CprOptions } from 'cpr';
Expand Down Expand Up @@ -56,9 +52,7 @@ export type {
LambdaTransformerInput,
LambdaTransformerOutput,
} from './wrappers/awsTransformerLambda';
export type { WhookCompilerConfig, WhookCompilerOptions, WhookCompilerService };

export { DEFAULT_COMPILER_OPTIONS, DEFAULT_BUILD_OPTIONS };
export const DEFAULT_BUILD_PARALLELISM = 10;

export type WhookBuildConfig = {
Expand Down
220 changes: 0 additions & 220 deletions packages/whook-aws-lambda/src/services/compiler.ts

This file was deleted.

Loading

0 comments on commit bdfcd2f

Please sign in to comment.