Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

372
Vistas
Webpack 5 import images and fonts, rewrite url in prod

I need to copy the image and font files to the appropriate folder in the dist directory, the problem is that in the final css file I get the wrong url path. I tried to disable url css-loader then files are not copied at all. Tried adding ~ to url . I need to use asset/resource to copy and paste the correct path in the stylesheet. Various other outdated solutions won't work for me.

My webpack 5 config

I import file less to main.js.

My folder structure

MY STRUCTURE

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Customize the publicPath to point to the folder from where your static files are served.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I solved my problem by adding publicPath: ".", why is there a dot in quotes? Because I have the path ./ in the url itself, so I add a dot and I can exit the directory.

For fonts, I created a generator that creates a separate folder, paths work on the same principle.

output: {
    path: path.resolve(__dirname, "dist"),
    publicPath: ".",
    assetModuleFilename: "./img/[name].[ext]",
    clean: true,
  },
  
  {
        test: /\.(jpe?g|png|gif|svg)$/i,
        type: "asset/resource",
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/i,
        type: "asset/resource",
        generator: {
          filename: "./fonts/[name][ext]",
        },
      },

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda