-
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.741s ± 0.040s [User: 3.331s, System: 0.218s] Range (min … max): 2.680s … 3.006s 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
d0a19fc
commit 2cf10e1
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.