2015-04-28 33 views
1

如果我運行webpack-dev-server,然後轉到localhost:8080,我的應用程序加載樣式。然而,CSS樣式顯示在單個div的「樣式」屬性上,而不是標題內,我認爲這是'反應式'的要點。React-Style不適用於webpack-dev-server。風格不提取。獲取'不變的違規:_registerComponent(...):目標

我生成的HTML:

<html><head> 
    <style type="text/css"></style></head> 
    <body style="zoom: 1;"> 
    <div id="app"><div data-reactid=".0"><div style="height:200px;width:200px;border:1px solid black;" data-reactid=".0.0"><div data-reactid=".0.0.0"></div><div style="text-align:center;font-size:10px;" data-reactid=".0.0.1">new</div></div></div></div> 
    <script src="bundle.js"></script> 

</body></html> 

此外,如果我不是我去http://localhost:8080/webpack-dev-server/bundle我得到這個以下錯誤:

Uncaught Error: Invariant Violation: _registerComponent(...): Target container is not a DOM element. 

這裏是我的index.html:

<!doctype html> 
<html> 
    <head> 
    </head> 
    <body> 
    <div id="app"></div> 
    <script src="bundle.js"></script> 
    </body> 
</html> 

webpack.config.js:

'use strict'; 

module.exports = { 
    entry: './modules/main.js', 
    output: { 
    filename: 'bundle.js', 
    }, 
    module: { 
    loaders: [ 
     { 
     test: /\.js$/, 
     loader: 'jsx-loader?harmony' 
     }, 
     { 
     test: /\.less$/, 
     loader: 'style-loader!css-loader!less-loader' 
     }, 
     { 
     test: /\.css$/, 
     loader: 'style-loader!css-loader' 
     }, 
     { 
     test: /\.(png|jpg)$/, 
     loader: 'url-loader?limit=8192' 
     } // inline base64 URLs for <=8k images, direct URLs for the rest 
    ] 
    } 
}; 

mains.js:

/** @jsx React.DOM */ 

var React = require('react'); 
var HoverAction = require('./HoverAction/HoverAction'); 

var Application = React.createClass({ 
    render: function() { 
    return (
     <div> 
     <HoverAction title="new"/> 
     </div> 
    ); 
    } 
}); 


if (typeof window !== 'undefined') { 
    React.render(<Application />, document.getElementById('app')); 
} 

HoverAction.js:

/** @jsx React.DOM */ 
'use strict'; 

var StyleSheet = require('react-style'); 
var React = require('react'); 

var HoverAction = React.createClass({ 
    render: function() { 
     return (
      <div style={HoverActionStyles.normal}> 
       <div ></div> 
       <div style={HoverActionTitleStyle.normal} >{this.props.title}</div> 
      </div> 
     ); 
    } 
}); 

var HoverActionStyles = StyleSheet.create({ 
    normal: { 
     height: '200px', 
     width: '200px', 
     border: '1px solid black'   
    } 
}); 

var HoverActionTitleStyle = StyleSheet.create({ 
    normal: { 
     textAlign: 'center', 
     fontSize: '10px'   
    } 
}); 

module.exports = HoverAction; 

回答

0

你應該綁定風格通過風格道具,不風格