I am new to webpack and would like to use it with reactjs, but now I have lost the confusion right now. I would like to know how css is processed in the process of developing a client site using webpack. I know that webpack combines all my js and bundles it like bundle.js, which I refer to in my html file as follows: <script src="http://localhost:3000/assets/bundle.js"></script> based on my webpack-dev server configuration. Now I also have a css file. Where is it going? so that my url refers to this in my html file. I understand that there is a style loader and css loader, as well as ExtractTextPlugin, but where is the way out? I saw that I can var css = require('path/customStyle.css') , but dos doesn't see where it appears? I do this in the index.jsx file. So the question is: how to do this, I can refer to my customStyle.css. What am I doing wrong or what will I skip Here is my project folder structure:
|_source | |_js | |_js | | |_components | | |_ *.jsx | |_index.jsx |_assets | |_css | |_customStyle.css |__index.html
My webpack.config.js is as follows
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") ] }
The html file is as follows:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="../node_modules/react/dist/react-with-addons.js"></script> </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 web package works and how to get my styles would be fantastic.
source share