2.0.0 • Published 3 years ago

@uqt/ng-node v2.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

@uqt/ng-node

Angular CLI Builder for building and executing node applications.

Why this package

With the stable release of Angular CLI Builders API (angular v8), the Angular CLI can be extended to run custom build targets.

It is common in monorepo design have both frontend and backend applications in the same repository, sharing common code. Most builders tend to use WebPack to build server applications as well as not catering for other non JavaScrip files (i.e. .graphql schema files).

Check out Nrwl for more info on monorepos and the amazing tools they provide to support them

Angular CLI Builders

Two builders are provided with this package. A build and execute builder.

The build builder will:

  1. Compile your TypeScript code
  2. Re-write and replace the TypeScrip alias paths (@some/alias) to relative paths(../../some/relative/paths) using @uqt/ts-path-replace
  3. Copy all non TypeScript (.ts) files from the project rooDir to the outDir
  4. The builder will exit once steps 1 - 3 complete.

The execute builder will:

  1. Compile your TypeScript code
  2. Re-write and replace the TypeScrip alias paths (@some/alias) to relative paths(../../some/relative/paths) using @uqt/ts-path-replace
  3. Copy all non TypeScript (.ts) files from the project rooDir to the outDir
  4. Run your application
  5. Watch for changes in the source files and repeat the steps 1 - 4 on each change

Installation

npm install --save-dev @uqt/ng-node

Usage

To use the custom builders, configure your angular.json like such.

// angular.json
{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  ...
  "projects":{
    ...
    "<PROJECT_NAME>": {
      ...
      "architect": {
        "build": {
          "builder": "@uqt/ng-node:build", // Use the 'build' target when building
          "options": {
            "tsConfig": "apps/servers/api/tsconfig.app.json"
            "outputPath": "dist/api",
            "src": "apps/servers/api/src",
          }
        },
        "serve": {
          "builder": "@uqt/ng-node:execute", // Use the 'execute' target when serving as the serve builder
          "options": {
            "tsConfig": "apps/servers/api/tsconfig.app.json",
            "outputPath": "dist/api",
            "src": "apps/servers/api/src",
            "main": "main.js",
            "envPath": "apps/servers/api/.env" // Optional path to environment variables
          }
        }
      }
    }
  }
}

Then run the commands with the Angular CLI as you normally would.

# Build once can complete
ng build <PROJECT_NAME>

# Build, run the application and watch for changes in the output and recompile
ng serve <PROJECT_NAME>

API Documentation

Options \<Object>

OptionBuilderDescription
tsConfigBuild / ExecutePath to the json config file to process Required
outputPathBuild / ExecutePath to the output directory of the project Required
srcBuild / ExecutePath to the src directory of the project Required
mainExecuteThe main entry point to the application (the file to execute) Required
envPathExecuteOptional path to an environment variable file Optional

Example

For an example of using these builders in a code sharing monorepo that includes a frontend written in Angular and a backend written in Koa that includes GraphQL, please see zero-to-production.dev

Versioning

The package follows semver versioning and releases are automated by semantic release

Contributing

Contributions and PR's are welcome!

Commit Message Guidelines

https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit

2.0.0

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.6

4 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago