react-boilerplate: Webpack Error when trying to pack CSS
I have to include statically a library (cesium) which does not support RequireJS. I have managed to get webpack to package this file by:
- putting this library under a new directory named
libunderapp - adding the following to my
app.js:
// Import for cesium
window.CESIUM_BASE_URL = './lib';
require('./lib/Cesium/Cesium.js');
require('./lib/Cesium/Widgets/widgets.css');
var Cesium = window.Cesium;
- and adding the following loader to
internals/webpack/webpack.base.babel.js:
{ test: /Cesium\.js$/, loader: 'script-loader' }
If I remove the require('./lib/Cesium/Widgets/widgets.css'); line from app.js, webpack builds fine and I can access the global Cesium object that this library creates.
However, requiring the CSS seems to give me the following error when running npm start:
ERROR in ./app/lib/Cesium/Widgets/widgets.css
Module parse failed: /home/balajeerc/Projects/ReactTest/app/lib/Cesium/Widgets/widgets.css Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| .my-custom-selector {
| color: red;
| text-align: center;
@ ./app/app.js 24:0-43
@ multi main
I have stripped the CSS down in this file to just the following to make sure it isn’t really anything specific to the CSS itself that is causing the problem:
.my-custom-selector {
color: red;
text-align: center;
}
I have made sure that I have the css-selector and style-selector packages installed.
Could someone please point out what it is that I am doing wrong?
Versions
- React-Boilerplate: 3.4.0
- Node: 6.9.1
- npm: 3.10.8
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (6 by maintainers)
Hello! Do you have in webpack config loaders for css files?
@KarandikarMihir
Actually, I cloned the boilerplate source code from the master branch. webpack config
/internals/webpack/webpack.base.babel.jsfile has below part of code to load .CSS file,To load our own custom CSS files, I added
instead of
For more information please look into this - https://github.com/react-boilerplate/react-boilerplate/pull/1599#issuecomment-280843785
@KarandikarMihir Thanks for taking time to reply, I followed as you suggested in the above comment, now I’m getting
One more 😃, As per the doc - https://github.com/react-boilerplate/react-boilerplate#features Instant feedback, if I’m right if I change any .js file, let us take footer.js file, it should render automatically in the browser, but its not rendering until unless I start the server again npm start
Please refer to css docs
@KarandikarMihir
Could you please suggest few GitHub repo’s which are using React boilerplate. So it might help us.
@bharadwajag Great. Can you post the exact problem and how you solved it? It might help others too.
Hello, Me also facing the same problem, while I’m trying to include .css file in one of my components, getting below error.