Coder Social home page Coder Social logo

Comments (4)

ardaorkin avatar ardaorkin commented on April 28, 2024 1

I solved the problem.
In my app.js file in the root folder of the project, I add this line to serve static CSS file with Express:
app.use(express.static("assets"));
This means Express will serve static file within the assets directory. Check it out for more info.
Then I copy /node_modules/bootstrap/dist/css/bootsrap.min.css file to /assets/css/ directory.
Finally in the jsx file which will be rendered, I add these line to require react-bootsrap module:
const Bootstrap = require("react-bootstrap");
And add the link tag in returned JSX:
<link rel="stylesheet" href="/css/bootstrap.min.css"></link>

So finally app.js file has been like that:

const express = require("express");
const app = express();
const path = require("path");
require("dotenv").config();

const about = require("./routes/about");
const works = require("./routes/works");
const port = process.env.PORT || 8000;

app.set("views", __dirname + "/views");
app.set("view engine", "jsx");
app.engine("jsx", require("express-react-views").createEngine());

app.use(express.static("assets"));

app.use("/works", works);

app.use("/about", about);

app.listen(port, () => {
  console.log(`Server listening on port: ${port}`);
});

And JSX file has been like that:

const React = require("react");
const Bootstrap = require("react-bootstrap");

const About = (params) => {
  return (
    <div>
      <link rel="stylesheet" href="/css/bootstrap.min.css"></link>
      <img src="/images/zebra.jpeg"></img>
      <Bootstrap.Button variant="primary">Primary</Bootstrap.Button>{" "}
    </div>
  );
};

module.exports = About;

from express-react-views.

orar avatar orar commented on April 28, 2024

I tried doing same with tailwindcss and failed.
This ll be possible if there's a way to use postcss when bundling views to import the css.
But I dont know how yet.

from express-react-views.

ardaorkin avatar ardaorkin commented on April 28, 2024

+1

from express-react-views.

ForInterviews1988 avatar ForInterviews1988 commented on April 28, 2024

I Used webpack to compile bootstrap.css into a javascripted form (->bootstrap.js). this is how i got rid of the above problem under nodeJS

from express-react-views.

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.