angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

@ngtools/webpack Conflict between DefinePlugin and AngularCompilerPlugin

Open daniel-nagy opened this issue 8 years ago • 8 comments

Variables defined by the Webpack DefinePlugin are not available to the config object of the RouterModule.

Versions

@angular/compiler: 5.1.2
@angular/compiler-cli: 5.1.2

Repro steps

// webpack config
new DefinePlugin({
  PRODUCTION: Boolean(env.production)
}),
// app module
const router = RouterModule.forRoot([...], {
  enableTracing: !PRODUCTION
});

@NgModule({
  imports: [
    router
  ]
})
export class AppModule {

}

Observed behavior

The value of PRODUCTION as defined by the DefinePlugin is not used and enableTracing is always true.

Desired behavior

I should be able to configure the RouterModule using variables defined by the DefinePlugin.

Mention any other details that might be useful (optional)

The following test.zip file contains a minimal project to reproduce the issue. Download the zip file then run

npm install
npm start

Open a browser to localhost:3000 and notice that the router events are always logged to the console regardless of the value of PRODUCTION as defined in the webpack.config.js file.

daniel-nagy avatar Jan 01 '18 05:01 daniel-nagy

how about using env.production instead? imported from environment.ts more here https://github.com/angular/angular-cli/wiki/stories-application-environments

Toxicable avatar Jan 02 '18 05:01 Toxicable

I’m not using the Angular CLI. Will the AngularCompiler Wepack plugin look for an .angular-cli.json file?

The environment file approach won’t allow for code elimination when minified, unlike the DefinePlugin.

daniel-nagy avatar Jan 02 '18 16:01 daniel-nagy

This only happens when ENV variables are used in decorators' metadata.

vagonpidarasov avatar Jan 03 '18 16:01 vagonpidarasov

Duplicate of #9051.

dgp1130 avatar May 30 '20 00:05 dgp1130

Duplicate of #9051.

Duplicates itself?

atamansv avatar Jun 02 '20 21:06 atamansv

Apologies, should be duplicate of #9874. Must have copy-pasted from the wrong tab.

dgp1130 avatar Jun 02 '20 22:06 dgp1130

Subscribe. I pass env variables in my webpack to server and Angular AOT client. Everything is fine on server, but client env are empty {}.

ghost avatar Jun 11 '20 21:06 ghost

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.