1

We just recently ported an Angular Project from angular 1.5 to 11. A part of the code was conditionally compiled with gulp-preprocess and conditional statements in code and templates (different parts were thrown out for special customers)

Unfortunatly something out of the box is not available for building Angular11 anymore. Currently i managed to use another preprocessor module webpack-preprocessor-loader and in combination with ngx-build-plus i created following plugin configuration for webpack:

exports.default = {
    pre: function (options) {

    },
    config: function (cfg) {
      const rule = {
        test: /\.ts$/,
        use: [
          {
            loader: 'webpack-preprocessor-loader',
            options: {
              params: {
                testParam: true,
              }
            }
          }
        ]
      }

      cfg.module.rules = [rule, ...cfg.module.rules];

      return cfg;
    },
    post: function (options) {

    }
};

If i now run ng serve or build the correct parts in the .ts files are changed.

My Problem is now, that i cant access the templates for the components (.html files) with this approach. Angular has already compiled them into their components.

Are there and hooks or build steps that i can access in Angular, that would let me run the preprocessor over the templates before they're compiled into the .ts component files?

Jenson
  • 625
  • 3
  • 16

0 Answers0