Angular Pug Builders adds pug (.pug
/ .jade
files) support for your Angular project.
It extends default @angular-devkit/build-angular builders with webpack pug rules. That means you always could you the latest (or a specific version) Angular native builders with Angular Pug Builders, because Angular Pug Builders uses @angular-devkit/build-angular
builders as a dependency.
Installation is simple as:
-
At the root of your project, run:
ng add ngx-pug-builders
Note: If you use older version of Angular, you need to install appropriate version of Angular Pug Builders. See Versioning.
Example: For Angular
v12.x.x
useng add ngx-pug-builders@12
-
That's it!
If you prefer manual installation, you would need:
-
Make sure your project have installed:
@angular-devkit/build-angular
@angular/compiler-cli
typescript
-
Install
ngx-pug-builders
andpug
as a development dependencies:npm install --save-dev ngx-pug-builders pug
or
npm i -D ngx-pug-builders pug
-
Switch
@angular-devkit/build-angular
builders to appropriatengx-pug-builders
builders in yourangular.json
.Before:
"builder": "@angular-devkit/build-angular:[browser|dev-server|extract-i18n|karma|server]"
After:
"builder": "ngx-pug-builders:[browser|dev-server|extract-i18n|karma|server]"
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.pug', // <--- Pug file supported now
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'app';
}
You can configure your project to pass the additional options to Pug loader.
You can see the supported options here.
Angular Pug Builders supports configuration files in several formats:
- JavaScript - use
.pugrc.js
orpug.config.js
and export an object containing your configuration. - YAML - use
.pugrc
, .pugrc.yaml
or.pugrc.yml
to define the configuration structure. - JSON - use
.pugrc.json
to define the configuration structure. - package.json - create an
pugConfig
property in yourpackage.json
file and define your configuration there.
If there are multiple configuration files in the same directory, Angular Pug Builders will only use one. The priority order is as follows:
package.json
.pugrc
.pugrc.json
.pugrc.yaml
.pugrc.yml
.pugrc.js
.pugrc.cjs
pug.config.js
pug.config.cjs
Here's an example configuration file that sets Pug loader basedir
option (again, see whole list of supported options here):
-
.pugrc.json
(JSON){ "basedir": "./src/" }
-
.pugrc
(YAML)# Unlike pug-loader, simple-pug-loader uses pug for all file resolution. basedir: ./src/
-
pug.config.js
(JavaScript)module.exports = { // Unlike pug-loader, simple-pug-loader uses pug for all file resolution. basedir: './src/' };
P.S.: Either of that should work. No need to create all of them. See Configuration File Formats.
Status | Name | Description |
---|---|---|
❌ | application | Build an Angular application targeting a browser and server environment using esbuild. |
❌ | app-shell | Build an Angular App shell. |
✔ | browser | Build an Angular application targeting a browser environment using Webpack. |
❌ | browser-esbuild | Build an Angular application targeting a browser environment using esbuild. |
✔ | dev-server | A development server that provides live reloading. |
✔ | extract-i18n | Extract i18n messages from an Angular application. |
✔ | karma | Execute unit tests using Karma test runner. |
❌ | ng-packagr | Build and package an Angular library in Angular Package Format (APF) format using ng-packagr. |
❌ | prerender | Prerender pages of your application. Prerendering is the process where a dynamic page is processed at build time generating static HTML. |
✔ | server | Build an Angular application targeting a Node.js environment. |
❌ | ssr-dev-server | A development server which offers live reload during development, but uses server-side rendering. |
❌ | protractor | Deprecated - Run end-to-end tests using Protractor framework. |
Versions started from v12 and are consistant with major Angular version used in your project. E.g.:
Use v17.x.x
with Angular 17.x.x
.
Use v16.x.x
with Angular 16.x.x
.
Use v15.x.x
with Angular 15.x.x
.
Use v14.x.x
with Angular 14.x.x
.
Use v13.x.x
with Angular 13.x.x
.
Use v12.x.x
with Angular 12.x.x
.
Run npm run build
to build the project. The build artifacts will be stored in the dist/
directory.