Skip to content

Webpack & Angular 7 #34

@tristanidoux

Description

@tristanidoux

Hello, first I wanted to thank you for this great module by the way, very useful :)

As I'm kind of a noob regarding webpack (I usually use ng-cli), I was wondering if it would be possible to have an example to make it work with Angular 7 ?

I installed the @angular-builders/custom-webpack package and can successfully have a custom webpack config. With the verbose activated, I can see the ifdef being detected but unfortunately the built app still contains the conditional blocks.

Here is my webpack config and my app :

custom-webpack-config.js:

var path = require('path');
var env = require("./src/environments/environment.json");


const opts = {
  env,
  DEBUG: true,
  "ifdef-verbose": true,       // add this for verbose output
};

console.log('Custom webpack config loaded');

module.exports = {
  entry: {
      main: './src/main.ts'
  },
  output: {
      path: path.resolve(__dirname, '../app/templates')
  },
  plugins: [],
  module: {
    rules: [{
      test: /\.tsx?$/,
      exclude: /node_modules/,
      use: [
        { loader: 'ts-loader' },
        { loader: 'ifdef-loader', options: opts }
      ],
    }]
  }
};

src/main.ts:

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.log(err));

/// #if DEBUG
console.log('Debug activated!');
/// #endif

I'm wondering if the output is not being overwritten by another part of the webpack. Could someone help me please ?

Thanks for your time !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions