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

132
Vistas
Is there a way to assign the content of a file to a specific variable using webpack?

Is there a way to assign the file contents directly to a variable/method without webpack generating an additional variable?

Currently webpack does something like this:

index.js

import scss from './styles.scss';
console.log(scss);

output.js (actual)

const styles = '...';
console.log(styles);

I want webpack to return the content of the styles.scss file directly to the console.log() method in the output without adding styles variable.

output.js (expected)

console.log('...');

I'm currently using my custom loader for reading .scss files:

css-loader.js

const sass = require('sass');

module.exports = function(source) {
    const result = sass.compile(this.resourcePath);

    return 'export default `\n' + result.css + '\n`';
};

I know there is a way to do this using the require() function but it generates a lot of extra code coming from webpack. Is there any other better way to do it?

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

0

So it's really a scoping issue. So there's no real requirement to not wanting webpacks default behaviour.

Webpack has a few ways how to do that. See this other answer for how to define a global variable, which is Webpacks way of doing what you want to do.

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