I am new to webpack and would like to use it with reactjs but kind of lost confused right now. I would like to know how css is handled in the client site development process with webpack. I know that webpack bundles all my js and links it as bundle.js which I reference in my html file like this:<script src="http://localhost:3000/assets/bundle.js"></script> based on my configuration of webpack-dev-server.
Now, I do have also a css file. Where does this go? what would be my url to reference this in my html file.
I understand that there is a style-loader and a css-loader and also an ExtractTextPlugin, but where does the output belong? I saw that I can var css = require('path/customStyle.css') but dos not seems to see where it appears? I do this in my index.jsx file.
So the question his: How to get this together, that I can reference my customStyle.css. What do I do wrong, or what do I miss
Here is my project folder structure:
|_source
| |_js
| |_js
| | |_components
| | |_ *.jsx
| |_index.jsx
|_assets
| |_css
| |_customStyle.css
|__index.html
My webpack.config.js looks like this
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: './source/js/index.jsx',
output: {
filename: 'bundle.js',
publicPath: 'http://localhost:8090/assets'
},
module: {
loaders: [
{
test: /\.jsx$/,
loader: 'jsx-loader?insertPragma=React.DOM&harmony'
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract("style-loader","css-loader")
}
]
},
externals: {
'react': 'React'
},
resolve: {
extensions: ['', '.js', '.jsx','.css']
},
plugins:[
new ExtractTextPlugin("styles.css")
]
}
Html file looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="../node_modules/react/dist/react-with-addons.js"></script>
<!-- like to link css here but don't know the path to link to -->
</head>
<body>
<div id="container">
</div>
<script src="http://localhost:3000/webpack-dev-server.js"></script>
<script src="http://localhost:3000/assets/bundle.js"></script>
</body>
</html>
Any help with some background on how the webpack way works and how to get my styles in would be fantastic.
extract-text-webpack-plugin,css-loader,html-webpack-pluginto organise the HTML, JSX, CSS files.