Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Adding CSS Loaders

Julia Janicki
Julia Janicki
6,278 Points

CSS not showing up when I import in app.js, only when I link it in index.html

Hello, I set up css loaders for my own project so I can import it in app.js instead of linking it in index.html. However, when I import it and use webpack-dev-server, my styles are not showing up, only when I try to link it in indexl.html it shows up, any idea why?

app.js:

import React from 'react'; import ReactDOM from 'react-dom'; import $ from 'jquery'; import './node_modules/bootstrap/dist/js/bootstrap.js'; import './node_modules/bootstrap/dist/css/bootstrap.css'; import './node_modules/font-awesome/css/font-awesome.css'; import "./css/style.css";

webpack.config.js (only the loader part):

module: { loaders:[ { test: /.js$/, exclude: /node_modules/, loader: 'babel-loader' }, { test:/.css$/, loader: 'style-loader!css-loader' }, { test: /.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' }, { test: /.(eot|woff|woff2|ttf|svg|png|jpe?g|gif)(\?\S*)?$/, loader: 'url?limit=100000&name=[name].[ext]' } ] }

Sergey Vrenev
Sergey Vrenev
28,778 Points

Try to add publicPath property, it should looks like this:

output: {
    path: '/',
    publicPath: '/build/',
    filename: 'bundle.js'
  },