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

101
Vistas
How to import images using webpack asset management in a javascript moodle activity plugin?

I am writing a moodle activity plugin that uses javascript. I am using webpack to bundle the javascript part of the project and then the bundled javascript file is required inside view.php by calling $PAGE->requires->js();. The view.php and the bundled javascript file are not inside the same directory.

The javascript part of the plugin will need to load some images. I wish to use the built-in Asset Modules of the webpack to load the images instead of an absolute path. I followed the guild in webpack documentation on asset management (https://webpack.js.org/guides/asset-management/#loading-images). However, It seems like the path is set incorrectly.

I wish to know how to load the image correctly using the webpack's asset management.

These are the screenshots of the HTTP response

Screenshot of the HTTP response when I am using an absolute path to load the image

Screenshot of the HTTP response when I am using webpack asset module to load the image

This is my webpack config file

const path = require('path');

module.exports = {
  mode: 'development',
  entry: {
    test: './src/test.js',
  },
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader'],
      },
      {
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
        type: 'asset/resource',
      },
    ],
  },
};

This is how I import the image inside the javascript file

import fullScreenButtonIcon from '../../assets/icon/fullscreen.png';

This is my project's structure

/srv/http/moodle/mod/assessmenttool/
├── tasks
│   ├── assets
│   │   └── icon
│   │       ├── fullscreen.png
│   │       └── ...
│   ├── dist
│   │   └── ...
│   ├── src
│   │   ├── test.js
│   │   └── ...
│   ├── package.json
│   ├── package-lock.json
│   └── webpack.config.js
├── view.php
└── ...
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