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

160
Vistas
How do I inject css imported in a javascript module into the html header using Gulp?

I've inherited a bit of a legacy system that uses Gulp, and am trying to bring in typescript, esmodules, and better dependency management. I'm running into a hurdle with javascript libraries that require css. In modern webpack based frameworks, I believe they implement css imports in js by injecting any imported css into the header in a large style tag. I'm trying to do a similar thing with Gulp.

I'd like to be able to convert this:

// src/index.html
<html>
  <head>
  </head>
  <body>
    <input type="text" />
    <!-- in src test.bundle.js is actually test.bundle.ts, but gets converted to js by gulp -->
    <script src="js/test.bundle.js"></script>
  </body>
</html>

To this:

//dist/index.html
<html>
  <head>
    <!-- This style auto-generated by gulp -->
    <style>... anything imported from js modules</style>
  </head>
  <body>
    <input type="text" />
    <script src="js/test.bundle.js"></script>
  </body>
</html>
// src/test.bundle.ts
import $ from 'jquery';
import 'jquery-typeahead';

//importing a css/scss file would inject it into the head in a style tag for any html page that brings in this script with <script src="js/test.bundle.js"></script>
import 'node_modules/jquery-typeahead/dist/jquery.typeahead.min.css';
...

If I should rethink my strategy, I'm open to that too. The current system is not a single page app with an entry point, so every html page is loaded in isolation, and gulp needs to treat each page as standalone.

Here's a POC that has the ts transpiling working for each independent page, but not a working solution for css importing: https://codesandbox.io/s/intelligent-dubinsky-oyc41?file=/src/test.bundle.ts

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