• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

364
Views
Angular: la variable webpack definePlugin no está definida

Estoy tratando de inyectar variables en mi código a través de definePlugin de Webpack.

Y después de leer numerosas publicaciones, nada parece funcionar. tengo la sensacion de que me falta algo...

La configuración de mi paquete web es:

 webpack = require('webpack'); module.exports = { plugins: [ new webpack.DefinePlugin({ $TEST: JSON.stringify(true), $ENV: { ENVIRONMENT: JSON.stringify(process.env.ENVIRONMENT) || 'localhost', API_URL: JSON.stringify(process.env.API_URL) } }) ] };

Creé el archivo typing.d.ts para declarar variables:

 declare let $ENV: Env; declare let $TEST: boolean; interface Env { ENVIRONMENT: string; API_URL: string; }

entonces estoy tratando de registrar variables en mi archivo main.ts:

 console.log('Test ' + $TEST); console.log('Environment :', $ENV.ENVIRONMENT);

Pero recibo el siguiente error cuando ejecuto el comando 'ng serve'

ingrese la descripción de la imagen aquí

Estoy usando :

  • paquete web: 5.54.0
  • "@constructores angulares/paquete web personalizado": "^12.1.2",
  • "@angular-devkit/build-angular": "~12.2.7",
  • "@angular/cli": "~12.2.7",

¿Alguien tiene alguna idea para arreglarlo por favor?

about 3 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto solo funcionará para ng build , para ng serve necesitaremos agregar otro constructor angular personalizado a nuestro angular.json:

 "serve": { "builder": "@angular-builders/custom-webpack:dev-server", "options": { "browserTarget": "app:build" }, "configurations": { "production": { "browserTarget": "app:build:production" }, "ci": { "progress": false } } },

Importante, algunas otras publicaciones mencionan el uso de @angular-builders/dev-server:generic builder.

Pero este está en desuso (ver migración de constructores angulares )

@angular-builders/dev-server:generic ha quedado obsoleto. Utilice @angular-builders/custom-webpack:dev-server en su lugar.

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error