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

194
Visualizações
django webpack loader setting to load css

It works when I set up like below. I am using django-webpack-loader

index.html

{% load render_bundle from webpack_loader %}
<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <title>Jayground</title>
        {% render_bundle 'main' 'css' %}
    </head>

    <body>
        <div id="react-app"></div>
        {% render_bundle 'main' 'js' %}
    </body>
</html>

Header.js

import styles from './header.css';

export default class Header extends React.Component {
    render(){
        <div className="header">
            hello
        </div>
    }
}

webpack.config.js (I made styles.css separately and then load css file in html separately so that className="header" works.)

config.plugins = config.plugins.concat([
    new ExtractTextPlugin('styles.css'),
]);

config.module.rules.push(
    {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
            use: 'css-loader'
        })
    }
)

According to what I understood, code below should work too. If I don't separate css file by using ExtractTextWebpackPlugin, bundle js file have css information in it like this.

exports.push([module.i, ".header {\r\n  background-color: blue;\r\n}\r\n\r\n.extra {\r\n\tfont-size: 50;\r\n}", ""]);

css should be loaded properly.

Header.js

import styles from './header.css';

export default class Header extends React.Component {
    render(){
        <div className={styles.header}>
            hello
        </div>
    }
}

webpack.config.js

config.module.rules.push(
    {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
    }
)

Do I miss something to work properly?

about 4 years ago · Santiago Trujillo
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