Code Monkey home page Code Monkey logo

ngx-pug-builders's Introduction

Angular Pug Builders

Build Publish npm version npm

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

Installation is simple as:

  1. 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 use

    ng add ngx-pug-builders@12
  2. That's it!

Manual installation

If you prefer manual installation, you would need:

  1. Make sure your project have installed:

    • @angular-devkit/build-angular
    • @angular/compiler-cli
    • typescript
  2. Install ngx-pug-builders and pug as a development dependencies:

    npm install --save-dev ngx-pug-builders pug

    or

    npm i -D ngx-pug-builders pug
  3. Switch @angular-devkit/build-angular builders to appropriate ngx-pug-builders builders in your angular.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]"

Usage

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';
}

Options

You can configure your project to pass the additional options to Pug loader.

You can see the supported options here.

Configuration File Formats

Angular Pug Builders supports configuration files in several formats:

  • JavaScript - use .pugrc.js or pug.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 your package.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:

  1. package.json
  2. .pugrc
  3. .pugrc.json
  4. .pugrc.yaml
  5. .pugrc.yml
  6. .pugrc.js
  7. .pugrc.cjs
  8. pug.config.js
  9. pug.config.cjs

Using Configuration Files

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.

Builders Support

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.

Dependencies

Versioning

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.

Build

Run npm run build to build the project. The build artifacts will be stored in the dist/ directory.

ngx-pug-builders's People

Contributors

lekhmanrus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ngx-pug-builders's Issues

Angular 15 support / breaking changes

Feature Description

Some infos on ngx-pug-builders and ng15

Tested with new angular 15, build / serve are OK.

ng test have problems as ng test outputs "Error: Specified patterns: "" did not match any spec files."

this is because of angular/angular-cli@dbcea96

two steps needed :

The first one is a one-liner into ngx-pug-builders code, the second one is changed by ng update, but not when using ngx-pug-builders, so it would eventually need a note in README ?

Until an ngx-pug-builders v15, changing tests.ts and calling ng test --include '**/*.ts' should be enough

Use Case

Use ngx-pug-builders with ng 15

Angular 15+ Template Concatenation

Documentation Feedback

Dear fellows,

I start by apologize as I know this might not be the best place to seek help.

Just noticed that your lib accomplish something I was looking for.

I need to get angular to concatenate templates in a component, and I could do that until v9- by simply using import template from './temp.html' and then at @component directive by template: template1 + template2 .. it used to work.

However I cant do that more in v13+

Could you provide me some help in order to achieve that?

Thank you so much

Angular 14

Feature Description

Angular 14 seems to be well supported by ngx-pug-builders using --force

warning " > [email protected]" has incorrect peer dependency "@angular-devkit/build-angular@^13.1.4".
warning " > [email protected]" has incorrect peer dependency "@angular/compiler-cli@^13.1.3".

could you release a ngx-pug-builders with 14 as peer dep ?
thank you for this valuable piece of code

Use Case

No response

Angular 16

Feature Description

ngx-pug-builders works perfectly with angular 16 (tested with all rc versions, and today with final 16.0.0), without any change. Could you bump the angular peer dep to allow smooth ng16 ng update without --force ? Thank you !

Use Case

No response

Provide basedir or root option to allow absolute paths for includes

Feature Description

First of all, thank you for your work on this project. I am migrating from ng-cli-pug-loader (thanks to your helpful reply on one of its issue threads) following the upgrade to Angular 12 and think this implementation is very nice. I did run into one big issue however but it seems like it should be pretty easy to solve.

Pug allows the use of 'include" to import pug templates from elsewhere in the source code. It is very convenient to be able to use absolute paths, relative to the root or base of the project, for these includes.

The former solution, ng-cli-pug-loader, did allow this style for includes, my project relied on it heavily. Btw, this project also had some issues with pug includes, see below for more info on that.

The dependency simple-pug-loader allows this style as well, however you have to provide that value for the basedir or root option in the loader config:

...
const addPugRules = (config) => {
     return webpack_merge_1.merge(config, {
        module: {
            rules: [
                {
                    test: /\.(pug|jade)$/,
                    use: [
                        { loader: 'apply-loader' },
                        { 
                            loader: 'simple-pug-loader', 
                            options: {
                                basedir: config.context // '/srv/deeply/nested/path/to/project/app'
                            }
                        }
                    ]
                }
            ]
        }
     });
  };
...

I am not entirely sure if this is actually an issue with the simple-pug-loader dependency or what, but it seems modifying the loader rules created by ngx-pug-builder's util.js file takes care of the problem for me at least.

FYI, I also noticed that the former project, ng-cli-pug-loader, had some issues with includes, specifically with apply-loader per this issue, and this was their solution:

function getPugLoaderRules(): string {
  const partialRegex = /\.(include|partial)\.(pug|jade)$/;
  return `
    {
      test: /\\.(pug|jade)$/,
      exclude: ${partialRegex},
      use: [
        { loader: "apply-loader" },
        { loader: "pug-loader" }
      ]
    },
    {
      test: ${partialRegex},
      loader: "pug-loader"
    },`.replace(/\s+/gm, ' ');
}

I'm not 100% clear on the why and how or if this even address the problem I am discussing or a different one, but hoping you know more than me, maybe you can make use of this information.

Let me know if there is anything else I can do, am interested to see how you think this should be addressed if at all.

Thanks again.

Use Case

I can keep my includes like so:

include /src/theme/templates/mixins/shared.include.pug

Instead of what would otherwise be a nightmare:

include ../../../../../../theme/templates/mixins/shared.include.pug

Angular 18 support?

Feature Description

Any progress to add new build for Angular18?
Thanks

Use Case

No response

Support for jest?

Feature Description

Hi, is there plan to support @angular-devkit/build-angular:jest ?

Use Case

No response

Karma tests issue

Feature Description

Hello.
I have the following karma configuration in karma.conf.js:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false,
      jasmine: {
        random: false
      }
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage'),
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    failOnEmptyTestSuite: false
  });
};

In angular.json:

...
"test": {
          "builder": "ngx-pug-builders:karma",
          "options": {
            "main": "src/main/angular/src/test.ts",
            "polyfills": "src/main/angular/src/polyfills.ts",
            "tsConfig": "src/main/angular/src/tsconfig.spec.json",
            "karmaConfig": "src/main/angular/src/karma.conf.js",
            "styles": [
              "src/main/angular/src/styles.styl"
            ],
            "scripts": [
              "node_modules/perfect-scrollbar/dist/perfect-scrollbar.js",
              "node_modules/@hrp/metronic-scripts/dist/scripts.bundle.js"
            ],
            "assets": [
              "src/main/angular/src/favicon.ico",
              "src/main/angular/src/assets"
            ],
            "fileReplacements": [
              {
                "replace": "src/main/angular/src/environments/environment.ts",
                "with": "src/main/angular/src/environments/environment.test.ts"
              }
            ]
          }
        }
...

Tests not working and print the following errors:

Error: Errors during JIT compilation of template for FinancialServicesComponent: Unexpected character "EOF" (Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.) ("
	ag-grid-angular.ag-theme-balham(appAgGrid, [gridOptions]="gridOptions", [columnDefs]="columnDefs")
	[ERROR ->]"): ng:///FinancialServicesComponent/template.html@22:0, Invalid ICU message. Missing '}'. (" type of documentTypes")
	        i.mr-3.fas.fa-business-time([ngClass]="type.color")
	        span [ERROR ->]{{type.name}}
	
	app-ag-grid-filters([gridOptions]="gridOptions")
	"): ng:///FinancialServicesComponent/template.html@18:13
	Error: Errors during JIT compilation of template for FinancialServicesComponent: Unexpected character "EOF" (Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.) ("
	ag-grid-angular.ag-theme-balham(appAgGrid, [gridOptions]="gridOptions", [columnDefs]="columnDefs")
	[ERROR ->]"): ng:///FinancialServicesComponent/template.html@22:0, Invalid ICU message. Missing '}'. (" type of documentTypes")
	        i.mr-3.fas.fa-business-time([ngClass]="type.color")
	        span [ERROR ->]{{type.name}}
	
	app-ag-grid-filters([gridOptions]="gridOptions")
	"): ng:///FinancialServicesComponent/template.html@18:13
	    at parseJitTemplate (node_modules/@angular/compiler/fesm2015/compiler.js:22746:1)
	    at CompilerFacadeImpl.compileComponent (node_modules/@angular/compiler/fesm2015/compiler.js:22555:43)
	    at Function.get (node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:27408:1)
	    at getComponentDef (node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:1120:1)
	    at node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:27206:1
	    at Array.forEach (<anonymous>)
	    at setScopeOnDeclaredComponents (node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:27202:1)
	    at flushModuleScopingQueueAsMuchAsPossible (node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:26887:1)
	    at TestBedRender3.checkGlobalCompilationFinished (node_modules/@angular/core/__ivy_ngcc__/fesm2015/testing.js:1815:53)
	    at TestBedRender3.resetTestingModule (node_modules/@angular/core/__ivy_ngcc__/fesm2015/testing.js:1665:1)

It's looks like that pug templates not compiling to the html code. But in development and production everything works ok. Thank you!

ngx-pug-builders version: 12.0.0
Angular version: 12

Use Case

No response

Support vscode + angular + pug

Feature Description

Hello,
Is a option to support pug template with angular on vs code ? Now is a problem with go to component by template reference (tag)

Is any option to resolve this problem in vs code ?

Use Case

If we have small project with a few component is not a problem because can use a vs code command line, but when we change a project to large/new where we have a lot of components is problem to find component, yes we can use a command line but sometimes the file name is not the same as template selector or we have multiple selector with the same name but in other modules.

Dev-Server compilation

Feature Description

Just upgraded to Angular v13 from v11, and was using another package for pug. I found your library, and it allows me to compile! thanks for all the work I am sure this took!

One thing that is driving me a little crazy though and even just using ng serve the compile result is like prod mode in that its all minified and what not. Makes debugging super annoying. I used to be able to put debuggers in the code and hit them, and Id love to be able to do so again.

Am I missing something in a config somewhere, or is this not supported?

Use Case

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.