Browse Source

feat(api): configure webpack plugin

pull/7198/head
KenTandrian 2 weeks ago
parent
commit
95a2e587ec
  1. 27
      apps/api/project.json
  2. 46
      apps/api/webpack.config.js
  3. 10
      nx.json

27
apps/api/project.json

@ -7,32 +7,7 @@
"generators": {},
"targets": {
"build": {
"executor": "@nx/webpack:webpack",
"options": {
"compiler": "tsc",
"deleteOutputPath": false,
"main": "apps/api/src/main.ts",
"outputPath": "dist/apps/api",
"sourceMap": true,
"target": "node",
"tsConfig": "apps/api/tsconfig.app.json",
"webpackConfig": "apps/api/webpack.config.js"
},
"configurations": {
"production": {
"generatePackageJson": true,
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/api/src/environments/environment.ts",
"with": "apps/api/src/environments/environment.prod.ts"
}
]
}
},
"outputs": ["{options.outputPath}"]
"outputs": ["{workspaceRoot}/dist/apps/api"]
},
"copy-assets": {
"executor": "nx:run-commands",

46
apps/api/webpack.config.js

@ -1,6 +1,44 @@
const { composePlugins, withNx } = require('@nx/webpack');
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
module.exports = composePlugins(withNx(), (config, { options, context }) => {
// Customize webpack config here
return config;
// These options were migrated by @nx/webpack:convert-to-inferred from
// the project.json file and merged with the options in this file
const configValues = {
build: {
default: {
compiler: 'tsc',
deleteOutputPath: false,
main: './src/main.ts',
outputPath: 'dist/apps/api',
sourceMap: true,
target: 'node',
tsConfig: './tsconfig.app.json'
},
production: {
generatePackageJson: true,
optimization: true,
extractLicenses: true,
inspect: false,
fileReplacements: [
{
replace: './src/environments/environment.ts',
with: './src/environments/environment.prod.ts'
}
]
}
}
};
// Determine the correct configValue to use based on the configuration
const configuration = process.env.NX_TASK_TARGET_CONFIGURATION || 'default';
const buildOptions = {
...configValues.build.default,
...configValues.build[configuration]
};
/**
* @type {import('webpack').WebpackOptionsNormalized}
*/
module.exports = async () => ({
plugins: [new NxAppWebpackPlugin(buildOptions)]
});

10
nx.json

@ -67,6 +67,16 @@
}
},
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"plugins": [
{
"plugin": "@nx/webpack/plugin",
"options": {
"buildTargetName": "build",
"serveTargetName": "serve",
"previewTargetName": "preview"
}
}
],
"targetDefaults": {
"build": {
"dependsOn": ["^build"],

Loading…
Cancel
Save