-
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.738s ± 0.031s [User: 3.325s, System: 0.218s] Range (min…max): 2.669s … 2.847s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 1.802s ± 0.013s [User: 1.761s, System: 0.140s] Range (min…max): 1.758s … 1.836s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.653s ± 0.009s [User: 0.786s, System: 0.134s] Range (min…max): 1.616s … 1.678s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#8900
- Loading branch information
1 parent
6ec676f
commit 5e04ab6
Showing
5 changed files
with
1,104 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,45 @@ | ||
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: [ | ||
// https://nx.dev/recipes/webpack/webpack-plugins#example | ||
new NxAppWebpackPlugin({ | ||
target: 'node', | ||
compiler: 'swc', | ||
main: './src/main.ts', | ||
tsConfig: './tsconfig.app.json', | ||
assets: ['./src/assets'], | ||
optimization: process.env['NODE_ENV'] === 'production', | ||
outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : '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.