All Projects â†’ mpolinowski â†’ gatsby-reactstrap

mpolinowski / gatsby-reactstrap

Licence: other
Adding Bootstrap 4 to an Gatsby React App and serve generated the static site with Express.js

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to gatsby-reactstrap

Gatsby Starter Netlify Cms
Example gatsby + netlify cms project
Stars: ✭ 1,932 (+7628%)
Mutual labels:  static-site-generator, gatsby, starter-template
Actions Gh Pages
GitHub Actions for GitHub Pages 🚀 Deploy static files and publish your site easily. Static-Site-Generators-friendly.
Stars: ✭ 2,576 (+10204%)
Mutual labels:  static-site-generator, gatsby
Gatsby Plugin Algolia
A plugin to push to Algolia based on graphQl queries
Stars: ✭ 154 (+516%)
Mutual labels:  static-site-generator, gatsby
Gatsby
Build blazing fast, modern apps and websites with React
Stars: ✭ 51,925 (+207600%)
Mutual labels:  static-site-generator, gatsby
Gatsby Starter Try Ghost
Publish flaring fast blogs with Gatsby and Ghost
Stars: ✭ 137 (+448%)
Mutual labels:  static-site-generator, gatsby
X0
Document & develop React components without breaking a sweat
Stars: ✭ 1,706 (+6724%)
Mutual labels:  static-site-generator, jsx
Post Scheduler
Schedule posts & content updates for static websites (Jekyll, Hugo, Gatsby, Phenomic etc)
Stars: ✭ 184 (+636%)
Mutual labels:  static-site-generator, gatsby
Gatsby Theme Try Ghost
A Gatsby theme to build flaring fast blogs from headless Ghost CMS
Stars: ✭ 88 (+252%)
Mutual labels:  static-site-generator, gatsby
roadbike
氏äčŠćŒ ćź˜çœ‘捹漱æșç 
Stars: ✭ 46 (+84%)
Mutual labels:  static-site-generator, gatsby
pothole detection
By using this app users can report the potholes on road by clicking a photo via our app and if a pothole is detected by Machine Learning modal then it is saved to our Database from where officials can view the specifics like location,reported by and official can resolve the request.User are notified by email for every update regarding their request
Stars: ✭ 17 (-32%)
Mutual labels:  expressjs, bootstrap4
lewis-gatsby-starter-blog
A custom Gatsby starter template to start a blog or personal website.
Stars: ✭ 34 (+36%)
Mutual labels:  gatsby, starter-template
Next Js Blog Boilerplate
🚀 Nextjs Blog Boilerplate is starter code for your blog based on Next framework. âšĄïž Made with Nextjs, TypeScript, ESLint, Prettier, PostCSS, Tailwind CSS.
Stars: ✭ 134 (+436%)
Mutual labels:  static-site-generator, starter-template
Jamstack Ecommerce
A starter project for building performant ECommerce applications with Next.js and React
Stars: ✭ 1,384 (+5436%)
Mutual labels:  static-site-generator, gatsby
sparky
A Bootstrap 3 and 4 Sass Starter Project
Stars: ✭ 21 (-16%)
Mutual labels:  starter-template, bootstrap4
Gen
Compositor JSX static site generator
Stars: ✭ 95 (+280%)
Mutual labels:  static-site-generator, jsx
Gatsby Docker
Develop & Build GatsbyJS static sites within Docker.
Stars: ✭ 184 (+636%)
Mutual labels:  static-site-generator, gatsby
Awesome Docs With Static Site Generators
Pointers to all templates and implementations based on static site generators
Stars: ✭ 44 (+76%)
Mutual labels:  static-site-generator, gatsby
Gatsby Advanced Starter
A high performance skeleton starter for GatsbyJS that focuses on SEO/Social features/development environment.
Stars: ✭ 1,224 (+4796%)
Mutual labels:  static-site-generator, gatsby
react-notification-alert
React bootstrap 4 notification alert
Stars: ✭ 34 (+36%)
Mutual labels:  bootstrap4, reactstrap
simple-webpack-starter
Webpack 4 starter project for rapid websites development with SASS, Bootstrap 4, ES6 & Docker.
Stars: ✭ 18 (-28%)
Mutual labels:  starter-template, bootstrap4

Gatsby.js & Bootstrap 4

Let's try to use the static site generator for React - Gatsby together with the Bootstrap 4 React components from reactstrap. To get started, I want to reproduce one of the official examples from getbootstrap.com.

Gatsby-reactstrap

Install Gatsby's command line tool

npm install --global gatsby-cli

Using the Gatsby CLI

  1. Create a new site. gatsby new gatsby-reactstrap
  2. cd gatsby-reactstrap
  3. gatsby develop — Gatsby will start a hot-reloading development environment accessible at localhost:8000

Install reactstrap

npm install [email protected] --save

npm install --save reactstrap@next

Optional Dependencies

These libraries are not included in the main distribution file reactstrap.min.js and need to be manually included when using components that require transitions or popover effects (e.g. Tooltip, Modal, etc).

Import the Components

Import Bootstrap CSS in the ./src/layouts/index.jsx file:

// import 'bootstrap/dist/css/bootstrap.min.css';

UPDATE: The import statement above works fine during development. But the Bootstrap CSS will not be imported when you build your static site - gatsby build

You can copy the minified CSS to into the ./src/layouts folder and change the import accordingly:

import './bootstrap.min.css';

Import required reactstrap components within your custom component files e.g. ./src/components/ReactNavbar.jsx:

import {
  Collapse,
  Navbar,
  NavbarToggler,
  NavbarBrand,
  Nav,
  NavItem,
  NavLink,
  Button
} from "reactstrap";

And add the react class according the reactstrap documentation:

export default class ReactNavbar extends React.Component {
  constructor(props) {
    super(props);

    this.toggleNavbar = this.toggleNavbar.bind(this);
    this.state = {
      collapsed: true
    };
  }

  toggleNavbar() {
    this.setState({
      collapsed: !this.state.collapsed
    });
  }
  render() {
    return <div>
        <Navbar color="dark" light>
          <NavbarBrand to="/" className="mr-auto">
            <img src="/static/instar-logo-s.png" />
          </NavbarBrand>
          <NavbarToggler onClick={this.toggleNavbar} className="mr-2" />
          <Collapse isOpen={!this.state.collapsed} navbar>
            <Nav navbar>
              <NavItem>
                <Link to="/">
                  <Button color="primary" block>
                    Indoor Cameras
                  </Button>
                </Link>
              </NavItem>
              <NavItem>
                <Link to="/page-2/">
                  <Button color="primary" block>
                    Outdoor Cameras
                  </Button>
                </Link>
              </NavItem>
              <NavItem>
                <NavLink href="https://github.com/mpolinowski/gatsby-reactstrap" target="_blank">
                  <Button color="danger" block>
                    Github Repository
                  </Button>
                </NavLink>
              </NavItem>
            </Nav>
          </Collapse>
        </Navbar>
      </div>;
  }
}

This component can then be imported into any page or layout you want:

import ReactNavbar from '../components/ReactNavbar'
[...]
<ReactNavbar />

Testing your build

Stop the development process and type in the following command to build the static version of your React App:

gatsby build

To quickly check your build, you can use httpster:

npm install httpster -g

Then run your build on localhost:3000 - e.g. if you have your repository in E:\gatsby-reactstrap - by typing:

httpster -p 3000 -d /e/gatsby-reactstrap/public

For Windows User: I noticed that httpster does not seem to like my Hyper Terminal - it runs fine in Git Bash.

Setting up a Webserver

I want to use Express.js to serve the generated static files:

npm install express --save
npm install compression --save

Add an index.js file to the root directory of your app ./index.js and copy in the following code to serve the ./public folder on localhost:8888:

const express = require("express");
const app = express();
const compression = require("compression");
// compress all responses
app.use(compression());

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

app.listen(8888, () => console.log("gatsby-reactstrap listening on http://localhost:8888"));

Now add a start script to your ./package.json file to allow you to start your server by typing npm start:

[...],
  "scripts": {
    "start": "node ./index.js"
  },
[...]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].