Prise en main Avec le stylet-chargeur pour Webpack

Bien (nouveau):

J'ai juste ajouté mon stylus-loader, style-loader (tel que recommandé par stylus-loader), et le chargeur { test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' } à la webpack config. Maintenant sur mon Main.js fichier, je suis en ajoutant var css = require('!css!stylus!./Main.styl');. Donc, je devrais être en train de voir la compilation des css dans le html, maintenant ? Ne sais pas si je suis de ce droit.

webpack.config.js

webpackConfig = {
    context: __dirname,
    entry: {
        app: ['webpack/hot/dev-server','./index.js']
    },
    output: {
        path: __dirname,
        filename: 'bundle.js'
    },
    module: {
        loaders: [
            { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'},
            { test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' }
        ]
    }
}

module.exports = webpackConfig;

index.js

var React = require('react');
var Main = require('./App/Components/Main');

class App extends React.Component{
    render(){
        return (
            <Main />
        )
    }   
}

React.render(<App />, document.getElementById('main'));

Main.js

'use strict'

import React from 'react';
import ReactCanvas from 'react-canvas';
var css = require('!css!stylus!./Main.styl'); 

var {
    Surface
} = ReactCanvas;

class Main extends React.Component{
    constructor() {
        super();
        this.size = document.getElementById('main').getBoundingClientRect() 
    }

    render() {
        return (
            <Surface top={0} left={0} width={this.size.width} height={this.size.height}>
            </Surface>
        )
    }
}

module.exports = Main

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>React Canvas</title>
</head>
<body>


    <header>
        <h1>React Canvas</h1>
    </header>

    <div id="main"></div>

    <script src="http://localhost:8080/webpack-dev-server.js"></script>
    <script src="bundle.js"></script>
</body>
</html>

OriginalL'auteur Alain Jacomet Forte | 2015-05-02