Coder Social home page Coder Social logo

Unable to load css about razzle HOT 11 CLOSED

jaredpalmer avatar jaredpalmer commented on September 24, 2024
Unable to load css

from razzle.

Comments (11)

rowellx68 avatar rowellx68 commented on September 24, 2024 5

@shoebmogal Here's how I've done it.

I installed the following packages:

  • extract-text-webpack-plugin
  • css-loader
  • sass-loader
  • style-loader

Here's an example of my webpack.config.dev.js

https://gist.github.com/rowellx68/362ceaeedf09c83c2b9c

You should then add this line in the server.js

<link rel="stylesheet" href="${ isDeveloping ? '/build/static/main.css' : assets.main.css}">

Then in the App component

if (typeof window !== 'undefined') {
  require('../css/core.scss');
  require('../css/theme.scss');
}

We need to wrap requiring the scss files so we don't get a syntax error when we start the server.

from razzle.

rowellx68 avatar rowellx68 commented on September 24, 2024 1

The issue seems to stem from you requiring flexboxgrid directly inside Grid.js. After trying it out myself, what you could do is @import flexboxgrid in your own css instead.

I have this in my webpack.config

resolve: {
    modulesDirectories: [ 'node_modules' ]
}

More info about resolve.moduleDirectories --> here

Then inside my own css file I just imported it as below:

@import "~flexboxgrid/dist/flexboxgrid";

And here's the module loader for my css and scss

{
    test: /\.(s?css)$/,
    loader: ExtractTextPlugin.extract("style-loader", "css-loader!sass-loader")
}

Of course you will require the correct loaders and plugin for it to work. 😄

from razzle.

rowellx68 avatar rowellx68 commented on September 24, 2024

Are you just looking for plain CSS or SASS as well?

from razzle.

jaredpalmer avatar jaredpalmer commented on September 24, 2024

Just extract your css to build/static folder and include the link to the extracted css file the same way the js files are referenced in server.js. Remove aphrodite, etc.

from razzle.

shoebmogal avatar shoebmogal commented on September 24, 2024

@rowellx68 yes I am trying to use extensions which use CSS and SASS.

@jaredpalmer I ll try that. But an example would be helpful. I tried to use css-loader , sass loader and give the directory in "includes" of the webpack config. Doesnt help

from razzle.

shoebmogal avatar shoebmogal commented on September 24, 2024

I ll give it a try @rowellx68 ! Thanks for all the help, will respond with my results and close thid issue.

from razzle.

shoebmogal avatar shoebmogal commented on September 24, 2024

Hi @rowellx68 , I tried doing all of that didnt work :(
Here's the error:

/Users/../react-production-starter/node_modules/flexboxgrid/dist/flexboxgrid.css:1
(function (exports, require, module, __filename, __dirname) { .container-fluid,
^

SyntaxError: Unexpected token .
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:404:25)
at Module._extensions..js (module.js:432:10)
at Object.require.extensions.(anonymous function) as .js
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object. (..../react-production-starter/node_modules/react-flexbox-grid/lib/components/Grid.js:13:20)
at Module._compile (module.js:425:26)

from razzle.

shoebmogal avatar shoebmogal commented on September 24, 2024

Thanks for the response @rowellx68 but its an external module that I am importing.
Infact any model that has css in it is failing with similar error.

from razzle.

jaredpalmer avatar jaredpalmer commented on September 24, 2024

@shoebmogal You'll need style-loader and css-loader to support plain css, even in external modules.

from razzle.

jaredpalmer avatar jaredpalmer commented on September 24, 2024

I am closing this issue and opening a PR for a recipes folder.

from razzle.

fahamidev avatar fahamidev commented on September 24, 2024

@shoebmogal do you solved your problem ?
I've same problem . And I do not know what is the solution ?

@shoebmogal @rowellx68 I opened a issue(532) about this. Thanks if you know the solution and answer that.

from razzle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.