Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

276
Visualizações
Import CSS to Typescript > JS for webpack w/o breaking src JS

I have a module main.ts that calls import './style.css' at the top. This is transpiled to the same import statement in the ES6 emitted by Typescript. I'm running Webpack w/ style-loader on the JS output. This works fine and builds the CSS into the final dist/main.js output.

However, this means that my src/ JS is now broken, as it has this import call at the top. Specifically, when I want to run out of src/ I get this:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/css". Strict MIME type checking is enforced for module scripts per HTML spec.

I don't really want Webpack to be a necessary step in development, only when I deploy. It seems Webpack would follow the linkage if I used require.js, but I'd like to do this without resorting to require(). Is there some kind of meta-syntax or commenting I can use - or forced inclusions in webpack.config.js - to make Webpack include the CSS and let Javascript engines ignore it?

One thing I tried that does work is try { require(['style.css']); } catch (e) {} instead of the import. That way I don't actually need require. It just seems pretty silly.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda