nippur72 / ifdef-loader

Webpack loader for JavaScript/TypeScript conditional compilation.
286 stars 28 forks source link

Has anyone gotten ifdef-loader to work with Angular 13? #62

Closed Yermo closed 2 years ago

Yermo commented 2 years ago

Title says it all. I'm trying to upgrade from Angular 10 to 13. Using the patch provided in another thread I had ifdef-loader working but it looks like the whole webpack setup has changed drastically in Angular 13 so the patch no longer works.

I've tried to use "ifdef-loader": "^2.3.0" with "@angular-builders/custom-webpack": "^13.0.0" using https://medium.com/angular-in-depth/customizing-angular-cli-build-an-alternative-to-ng-eject-v2-c655768b48cc as a guide.

My custom config is:


// ifdef-loader config

const opts = {
   APP: false,
   WEB: true,
   DEBUG: true,
   version: 3,
   "ifdef-verbose": true,                 // add this for verbose output
   "ifdef-triple-slash": true,           // add this to use double slash comment instead of default triple slash
   "ifdef-fill-with-blanks": true         // add this to remove code with blank spaces instead of "//" comments
   "ifdef-uncomment-prefix": "// #code "  // add this to uncomment code starting with "// #code "
};

module.exports = {
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        exclude: /node_modules/,
        use: [
          { loader: 'ts-loader' },
          { loader: 'ifdef-loader", options: opts }
        ]
      }
    ]
  },
....

My .ts files are not getting processed by ifdef-loader. 

Any hints or pointers at what I should look at next would be greatly appreciated.
Yermo commented 2 years ago

I've created a patch for @angular-devkit/build-angular/@ngtools/webpack 13.1.2 that calls ifdef-loader on all ts, html, and scss files in a project:

https://gist.github.com/Yermo/22143234bce8e9ab7a4711f7069f5178

It relies on:

"patch-package": "^6.2.2", "dotenv-parse-variables": "^1.0.1"