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

213
Vistas
React & Webpack - How to make local images folder public and redirect `src` from `img` to it?

The context

I'm working on a React project where the styles and the images are being provided by an external theme, as the React app will be embeded into a portlet inside this webpage. As so, the images inside the React app are relative and point to a directory which I don't have access to during development.

<img src="/relative/external/theme/images/themeImg.png" />

As I don't have access to it, when I develop locally I am not able to see any of those images. However, for development purposes I do have those image files locally in my src/js/images/ local directory.

We are using Webpack 4.

The current config

Here I leave part of the actual configuration (I cannot publish everything):

 {
    name: 'main',
    mode: 'development',
    devtool: 'source-map',
    output: {
      filename: 'main.js',
      path: path.resolve(__dirname, 'dist'),
    },
    entry: {
      main: './src/main/js/main.js',
    },
    module: {
      rules: [
        {
          test: /\.(js|jsx)$/,
          resolve: { extensions: ['.js', '.jsx'] },
          exclude: /node_modules/,
          loaders: ['babel-loader'],
        },
        {
          test: /\.svg$/,
          use: [
            {
              loader: 'svg-url-loader',
            },
          ],
        },
        { test: /\.css$/, loader: 'style-loader!css-loader' },
        {
          test: /\.scss$/,
          use: [
            {
              loader: 'style-loader',
            },
            {
              loader: 'css-loader',
            },
            {
              loader: 'sass-loader',
            },
          ],
        },
      ],
    },
    devServer: {
      contentBase: path.join(__dirname, 'dist'),
      port: 9000,
      historyApiFallback: true,
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods':
          'GET, POST, PUT, DELETE, PATCH, OPTIONS',
        'Access-Control-Allow-Headers':
          'X-Requested-With, content-type, Authorization',
      },
    }
  }

The question

Is there a way to which I can tell Webpack to make my src/js/images/ directory public, so it's accessible by the HTML src attributes, and redirect all relative/external/theme/images calls to that public images/ directory in development (without messing with publicPath so the whole bundle is still served from the same place)?

I cannot import images and use them in the src since I cannot import them from a directory I don't have access to, that's why the whole folder should be public and available to load the images from it.

about 4 years ago · Juan Pablo Isaza
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