-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(apps/app): Setup SWC build compilation
To speed up the build compilation. hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t lint" Time (mean ± σ): 2.765s ± 0.033s [User: 3.343s, System: 0.224s] Range (min … max): 2.694s … 3.007s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 1.816s ± 0.013s [User: 1.759s, System: 0.140s] Range (min … max): 1.792s … 1.883s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.667s ± 0.008s [User: 0.786s, System: 0.136s] Range (min … max): 1.629s … 1.688s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#8900
- Loading branch information
1 parent
263c82a
commit 7175602
Showing
5 changed files
with
1,103 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/swcrc", | ||
"sourceMaps": true, | ||
"module": { | ||
"type": "commonjs", | ||
"strict": true, | ||
"strictMode": true | ||
}, | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"decorators": true, | ||
"dynamicImport": true | ||
}, | ||
"transform": { | ||
"legacyDecorator": true, | ||
"decoratorMetadata": true | ||
}, | ||
"target": "es2021" | ||
}, | ||
"minify": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,44 @@ | ||
const { join } = require('path') | ||
const swcDefaultConfig = | ||
require('@nestjs/cli/lib/compiler/defaults/swc-defaults').swcDefaultsFactory() | ||
.swcOptions | ||
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin') | ||
const { merge } = require('webpack-merge') | ||
|
||
module.exports = { | ||
output: { | ||
path: join(__dirname, '../../dist/apps/app') | ||
}, | ||
plugins: [ | ||
new NxAppWebpackPlugin({ | ||
target: 'node', | ||
compiler: 'tsc', | ||
main: './src/main.ts', | ||
tsConfig: './tsconfig.app.json', | ||
assets: ['./src/assets'], | ||
optimization: false, | ||
outputHashing: 'none' | ||
}) | ||
] | ||
module.exports = () => { | ||
// Get the base Nx webpack config | ||
const baseConfig = { | ||
output: { | ||
path: join(__dirname, '../../dist/apps/app') | ||
}, | ||
plugins: [ | ||
new NxAppWebpackPlugin({ | ||
target: 'node', | ||
compiler: 'swc', | ||
main: './src/main.ts', | ||
tsConfig: './tsconfig.app.json', | ||
assets: ['./src/assets'], | ||
optimization: false, | ||
outputHashing: 'none' | ||
}) | ||
] | ||
} | ||
|
||
// Modify the base config to use swc-loader | ||
const customConfig = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.ts?$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: 'swc-loader', | ||
options: swcDefaultConfig | ||
} | ||
} | ||
] | ||
} | ||
} | ||
|
||
return merge(baseConfig, customConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.