GithubHelp home page GithubHelp logo

kriasoft / react-firebase-starter Goto Github PK

View Code? Open in Web Editor NEW
4.5K 91.0 753.0 4.98 MB

Boilerplate (seed) project for creating web apps with React.js, GraphQL.js and Relay

Home Page: https://firebase.reactstarter.com

License: MIT License

JavaScript 95.71% Dockerfile 0.37% Shell 1.77% EJS 2.16%
react boilerplate javascript reactjs hmr create-react-app relay relay-modern graphql spa

react-firebase-starter's Introduction

React Starter Kit for Firebase   a.k.a. Serverless Edition
Build Status Dependabot Twitter

React Starter Kit for Firebase is a popular project template (aka, boilerplate) for building modern, scalable web applications with React, Relay, and GraphQL using serverless infrastructure provided by Google Cloud (Cloud SQL, Cloud Functions, CDN hosting, and file storage). It allows you to save time and build upon a solid foundation and design patterns.

View online demo (API, data model)  |  Follow us on Twitter  |  Get FREE support on Discord  |  We're hiring!

    


This project was bootstrapped with React Starter Kit for Firebase by Kriasoft.

Tech Stack

Also, you need to be familiar with HTML, CSS, JavaScript (ES2015) and React.

Directory Layout

├── build/                         # Compiled output
├── migrations/                    # Database schema migration files
├── node_modules/                  # 3rd-party libraries and utilities
├── public/                        # Static files such as favicon.ico etc.
├── scripts/                       # Automation scripts (yarn update-schema etc.)
├── src/                           # Application source code
│   ├── admin/                     # Admin section (Dashboard, User Management etc.)
│   ├── common/                    # Shared React components and HOCs
│   ├── hooks/                     # React.js hooks and Context providers
│   ├── icons/                     # Icon components
│   ├── legal/                     # Terms of Use, Privacy Policy, etc.
│   ├── misc/                      # Other pages (about us, contacts, etc.)
│   ├── mutations/                 # GraphQL mutations to be used on the client
│   ├── news/                      # News section (example)
│   ├── server/                    # Server-side code (API, authentication, etc.)
│   │   ├── mutations/             # GraphQL mutations
│   │   ├── queries/               # The top-level GraphQL query fields
│   │   ├── templates/             # HTML templates for server-side rendering
│   │   ├── types/                 # GraphQL types: User, UserRole, UserIdentity etc.
│   │   ├── api.js                 # GraphQL API middleware
│   │   ├── app.js                 # Express.js application
│   │   ├── config.js              # Configuration settings to be passed to the client
│   │   ├── context.js             # GraphQL context wrapper
│   │   ├── db.js                  # PostgreSQL database client (Knex.js)
│   │   ├── relay.js               # Relay factory method for Node.js environment
│   │   ├── index.js               # Node.js app entry point
│   │   ├── login.js               # Authentication middleware (e.g. /login/facebook)
│   │   ├── schema.js              # GraphQL schema
│   │   └── ssr.js                 # Server-side rendering, e.g. ReactDOMServer.renderToString(<App />)
│   ├── user/                      # User pages (login, account settings, user profile, etc)
│   ├── utils/                     # Utility functions
│   ├── relay.js                   # Relay factory method for browser environment
│   ├── index.js                   # Client-side entry point, e.g. ReactDOM.render(<App />, container)
│   ├── router.js                  # Universal application router
│   ├── serviceWorker.js           # Service worker helper methods
│   └── theme.js                   # Overrides for Material UI default styles
├── ssl/                           # SSL certificates for connecting to Cloud SQL instance
├── .env                           # Environment variables for local development
├── .env.production                # Environment variables for the production build
├── .env.test                      # Environment variables for the test build
├── graphql.schema                 # GraphQL schema (auto-generated, used by Relay)
└── package.json                   # The list of project dependencies + NPM scripts

Prerequisites

Getting Started

Just clone the repo, update environment variables in .env and/or .env.local file, and start hacking:

$ git clone https://github.com/kriasoft/react-firebase-starter.git MyApp
$ cd MyApp
$ yarn setup                       # Installs dependencies; creates PostgreSQL database
$ yarn start                       # Compile the app and opens it in a browser with "live reload"

Then open http://localhost:3000/ to see your app.

npm start

In order to re-compile GraphQL fragments, run yarn relay or yarn relay --watch (in watch mode).

How to Migrate Database Schema

While the app is in development, you can use a simplified migration workflow by creating a backup of your existing database, making changes to the existing migration file (see migrations/20180101000000_initial.js), re-apply the migration and restore data from the backup file (backup.sql):

$ yarn db-backup --env=dev         # Or, yarn db-backup --env=test
$ yarn db-reset-dev                # Or, yarn db-reset-test

Upon deployment to production, switch to normal migration workflow:

$ yarn db-change <name>            # Create a new database migration file
$ yarn db-migrate --env=dev        # Migrate database to the latest version

HINT: Test your migration thoroughly with a local instance of the DB first (by using --env=local or --env=dev (default) flag) then apply it to your test or prod database instance using --env=test or --env=prod command argument.

Other helpful database scripts:

$ yarn db-version --env=dev        # Print the version number of the last migration
$ yarn db-rollback --env=dev       # Rollback the latest migration
$ yarn db-restore --env=dev        # Restore database from backup.sql
$ yarn db-seed --env=dev           # Seed database with test data
$ yarn db --env=dev                # Open Knex.js REPL shell (type ".exit" for exit)
$ yarn psql --env=dev              # Open PostgreSQL shell (type "\q" for exit)

How to Test

$ yarn lint                        # Check JavaScript and CSS code for potential issues
$ yarn lint-fix                    # Attempt to automatically fix ESLint warnings
$ yarn test                        # Run unit tests. Or, `yarn test -- --watch`

How to Deploy

$ yarn build                       # Build the in production mode (NODE_ENV=production)
$ yarn deploy-test                 # Deploy the app to TEST environment
$ yarn deploy-prod                 # Deploy the app to PROD environment

For more information refer to the Deployment guide in the project's Wiki.

How to Update

If you keep the original Git history after cloning this repo, you can always fetch and merge the recent updates back into your project by running:

$ git remote add rsk https://github.com/kriasoft/react-firebase-starter.git
$ git checkout master
$ git fetch rsk
$ git merge rsk/master
$ yarn install

NOTE: Try to merge as soon as the new changes land on the master branch in the upstream repository, otherwise your project may differ too much from the base/upstream repo. Alternatively, you can use a folder diff tool like Beyond Compare for keeping your project up to date with the base repository.

Backers

              

How to Contribute

Anyone and everyone is welcome to contribute to this project. The best way to start is by checking our open issues, submit a new issues or feature request, participate in discussions, upvote or downvote the issues you like or dislike, send pull requests.

Learn React.js and ES6

🎓   React for Beginners and ES6 Training Course by Wes Bos
📗   React: Up & Running: Building Web Applications by Stoyan Stefanov (Aug, 2016)
📗   Getting Started with React by Doel Sengupta and Manu Singhal (Apr, 2016)
📗   You Don't Know JS: ES6 & Beyond by Kyle Simpson (Dec, 2015)

Related Projects

  • React App SDK — Create React App modification that unlocks server-side rendering
  • React Starter Kit — Boilerplate and tooling for building isomorphic web apps with React and Relay
  • Node.js API Starter Kit — Boilerplate and tooling for building data APIs with Docker, Node.js and GraphQL

License

Copyright © 2015-present Kriasoft. This source code is licensed under the MIT license found in the LICENSE.txt file.


Made with ♥ by Konstantin Tarkus (@koistya, blog) and contributors 👋 Get in touch!

react-firebase-starter's People

Contributors

adityachugh avatar alerosa avatar andrewkslv avatar andrwh avatar b2whats avatar bardouni avatar bdefore avatar cle1000 avatar cobbweb avatar coryhouse avatar creeperyang avatar danyim avatar dax70 avatar dependabot-preview[bot] avatar ethanneff avatar filipchalupa avatar frenzzy avatar greenkeeper[bot] avatar handtrix avatar jdelafon avatar jfly avatar josephfrazier avatar koistya avatar krzysztofkarol avatar lacour avatar levymoreira avatar liesislukas avatar mksarge avatar nateeo avatar nazark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-firebase-starter's Issues

how to add client dependencies

like let's say i wanted to add bootstrap or ratchet or google maps. How would I do that?

seems like my assets have to end up in the /build folder, but where to prep them up so they end up there?

webpack error: '//' is an unknown word in _bootstrap.scss

I apologize if this is in the wrong place, but I'm not too familiar with webpack, and I can't tell if this is an issue with css-loader, postcss or something else.

After installing bootstrap-sass from NPM, I tried importing it in index.js and got this error:

ERROR in ./~/css-loader!./~/postcss-loader!./~/bootstrap-sass/assets/stylesheets/_bootstrap.scss
/home/itxchy/www/ccf-react/node_modules/bootstrap-sass/assets/stylesheets/_bootstrap.scss:7:1: Unknown word

// Core variables and mixins
^
@import "bootstrap/variables";

ERROR in ./~/css-loader!./~/postcss-loader!./~/bootstrap-sass/assets/stylesheets/_bootstrap.scss
Module build failed: TypeError: Cannot read property 'toString' of undefined
    at new Input (/home/itxchy/www/ccf-react/node_modules/postcss/lib/input.js:31:23)
    at parse (/home/itxchy/www/ccf-react/node_modules/postcss/lib/parse.js:22:17)
    at new LazyResult (/home/itxchy/www/ccf-react/node_modules/postcss/lib/lazy-result.js:61:24)
    at Processor.process (/home/itxchy/www/ccf-react/node_modules/postcss/lib/processor.js:34:16)
    at processCss (/home/itxchy/www/ccf-react/node_modules/css-loader/lib/processCss.js:165:11)
    at Object.module.exports (/home/itxchy/www/ccf-react/node_modules/css-loader/lib/loader.js:22:2)
 @ ./~/bootstrap-sass/assets/stylesheets/_bootstrap.scss 4:14-110 13:2-17:4 14:20-116

Here's index.js for reference. I only added the bootstrap import, a bootstrappy button, and a smaller index.scss file to test this:

  • index.js
import React, { Component } from 'react';
import '../node_modules/bootstrap-sass/assets/stylesheets/_bootstrap.scss';
import './index.scss';

export default class extends Component {

  render() {
    return (
      <div>
        <h1>Home Page</h1>
        <button type="button" class="btn btn-danger">Dangerous Button!</button>
        <p>Coming soon.</p>
      </div>
    );
  }
}

The index.scss file with a // comment plus a style worked just fine.

  • index.scss
@import '../components/variables.scss';

// test

h1 {
  font-size: 2em;
}

Any idea what's causing this?

Dynamic Pages?

Has anyone extended this boilerplate to generate pages from a json file, vs from files in the /pages directory?

What I'd like to do is have a /data/pages.json (which would get pulled in dynamically on build from a db, but let's walk before we run ;). Each page is composed of sections, which would be React components. Something like...

[
  {
    "name": "01",
    "sections": [
      {
        "template": "one-col",
        "headline": "page 1 section 1 headline",
        "cta": "page 1 section 1 cta"
      },
      {
        "template": "two-col",
        "headline": "page 1 section 2 headline",
        "cta": "page 1 section 2 cta"
      }
    ]
  },
  {
    "name": "02",
    "sections": [
      {
        "template": "two-col",
        "headline": "page 2 section 1 headline",
        "cta": "page 2 section 1 cta"
      },
      {
        "template": "one-col",
        "headline": "page 2 section 2 headline",
        "cta": "page 2 section 2 cta"
      }
    ]
  }
]

Looking at getPages in render.js, could extend the files object with any pages in /data/pages.json before iterating through, but maybe there's a better approach?

Any ideas?

ReferenceError: document is not defined

Hi, first thanks for your boilerplate!
I just have one problem when I try import react-youtube (https://github.com/troybetz/react-youtube). Note sure if it comes from the module itself or just a problem of configuration in my app but here is the stacktrace:

Starting 'render'...
ReferenceError: document is not defined
    at load ([..]/webapp/node_modules/load-script/index.js:3:14)
    at exports.default ([..]/webapp/node_modules/youtube-player/dist/es5/loadYouTubeIframeAPI.js:43:33)
    at Object.<anonymous> ([..]/webapp/node_modules/youtube-player/dist/es5/index.js:41:58)
    at Module._compile (module.js:434:26)
    at Module._extensions..js (module.js:452:10)
    at Object.require.extensions.(anonymous function) [as .js] ([..]/webapp/node_modules/babel-core/lib/api/register/node.js:214:7)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> ([..]/webapp/node_modules/react-youtube/dist/YouTube.js:23:22)
    at Module._compile (module.js:434:26)
    at Module._extensions..js (module.js:452:10)
    at Object.require.extensions.(anonymous function) [as .js] ([..]/webapp/node_modules/babel-core/lib/api/register/node.js:214:7)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

(I already tried to escape the serve side rendering with a canUseDom check but it changes nothing, the error occurs during the import..)

Thanks in advance for your help!
Thomas

How to debug?

How do I debug in Chrome DevTools? After npm start the code shown in Chrome DevTools is not readable.

screenshot 2015-09-26 12 23 38

It would be great if you can share a little bit about working with DevTool in react-static-boilerplate because I am falling in love with this.

can not run - unexpected token

Downloaded and set up as instructed. Does not run on my system, giving me this error:

@ start /Users/elliot/reactwork
babel-node --eval "require('./tools/start')().catch(err => console.log(err.stack))"

[12:16:11] Starting 'build'...
[12:16:11] Starting 'clean'...
[12:16:11] Finished 'clean' after 18ms
[12:16:11] Starting 'copy'...
[12:16:11] Finished 'copy' after 8ms
[12:16:11] Starting 'bundle'...
Child
Time: 2975ms

ERROR in ./pages/500.js
Module build failed: SyntaxError: /Users/elliot/reactwork/pages/500.js: Unexpected token (11:19)
   9 | export default class extends Component {
  10 | 
> 11 |   static propTypes = {
     |                    ^
  12 |     error: PropTypes.instanceOf(Error),
  13 |   };
  14 | 
    at Parser.pp.raise (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/location.js:24:13)
    at Parser.pp.unexpected (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/util.js:82:8)
    at Parser.pp.parseClassProperty (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:624:61)
    at Parser.parseClassProperty (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/plugins/flow.js:797:20)
    at Parser.pp.parseClass (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:567:32)
    at Parser.pp.parseExprAtom (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:405:19)
    at Parser.parseExprAtom (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/plugins/jsx/index.js:412:22)
    at Parser.pp.parseExprSubscripts (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:236:19)
    at Parser.pp.parseMaybeUnary (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:217:19)
    at Parser.pp.parseExprOps (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:163:19)
 @ ./app.js 41:11-36

ERROR in ./components/Link/Link.js
Module build failed: SyntaxError: /Users/elliot/reactwork/components/Link/Link.js: Unexpected token (21:19)
  19 | class Link extends Component {
  20 | 
> 21 |   static propTypes = {
     |                    ^
  22 |     to: PropTypes.string.isRequired,
  23 |     children: PropTypes.element.isRequired,
  24 |     state: PropTypes.object,
    at Parser.pp.raise (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/location.js:24:13)
    at Parser.pp.unexpected (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/util.js:82:8)
    at Parser.pp.parseClassProperty (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:624:61)
    at Parser.parseClassProperty (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/plugins/flow.js:797:20)
    at Parser.pp.parseClass (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:567:32)
    at Parser.pp.parseStatement (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:84:19)
    at Parser.parseStatement (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/plugins/flow.js:621:22)
    at Parser.pp.parseTopLevel (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:30:21)
    at Parser.parse (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/index.js:70:17)
    at Object.parse (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/index.js:45:50)
 @ ./components/Navigation/Navigation.js 21:12-30

Child
Time: 2319ms
Asset Size Chunks Chunk Names
app.node.js 33.2 kB 0 [emitted] main

ERROR in ./pages/500.js
Module build failed: SyntaxError: /Users/elliot/reactwork/pages/500.js: Unexpected token (11:19)
   9 | export default class extends Component {
  10 | 
> 11 |   static propTypes = {
     |                    ^
  12 |     error: PropTypes.instanceOf(Error),
  13 |   };
  14 | 
    at Parser.pp.raise (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/location.js:24:13)
    at Parser.pp.unexpected (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/util.js:82:8)
    at Parser.pp.parseClassProperty (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:624:61)
    at Parser.parseClassProperty (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/plugins/flow.js:797:20)
    at Parser.pp.parseClass (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:567:32)
    at Parser.pp.parseExprAtom (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:405:19)
    at Parser.parseExprAtom (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/plugins/jsx/index.js:412:22)
    at Parser.pp.parseExprSubscripts (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:236:19)
    at Parser.pp.parseMaybeUnary (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:217:19)
    at Parser.pp.parseExprOps (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:163:19)
 @ ./app.js 39:11-36

ERROR in ./components/Link/Link.js
Module build failed: SyntaxError: /Users/elliot/reactwork/components/Link/Link.js: Unexpected token (21:19)
  19 | class Link extends Component {
  20 | 
> 21 |   static propTypes = {
     |                    ^
  22 |     to: PropTypes.string.isRequired,
  23 |     children: PropTypes.element.isRequired,
  24 |     state: PropTypes.object,
    at Parser.pp.raise (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/location.js:24:13)
    at Parser.pp.unexpected (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/util.js:82:8)
    at Parser.pp.parseClassProperty (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:624:61)
    at Parser.parseClassProperty (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/plugins/flow.js:797:20)
    at Parser.pp.parseClass (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:567:32)
    at Parser.pp.parseStatement (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:84:19)
    at Parser.parseStatement (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/plugins/flow.js:621:22)
    at Parser.pp.parseTopLevel (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:30:21)
    at Parser.parse (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/parser/index.js:70:17)
    at Object.parse (/Users/elliot/reactwork/node_modules/babel-core/node_modules/babylon/lib/index.js:45:50)
 @ ./components/Navigation/Navigation.js 21:12-30

[12:16:14] Finished 'bundle' after 2997ms
[12:16:14] Starting 'render'...
Error: Cannot find module "../Link"
at webpackMissingModule (/Users/elliot/reactwork/build/app.node.js:297:79)
at Object.module.exports.Object.defineProperty.value (/Users/elliot/reactwork/build/app.node.js:297:163)
at webpack_require (/Users/elliot/reactwork/build/app.node.js:21:30)
at Object.module.exports.Object.defineProperty.value (/Users/elliot/reactwork/build/app.node.js:251:21)
at webpack_require (/Users/elliot/reactwork/build/app.node.js:21:30)
at Object. (/Users/elliot/reactwork/build/app.node.js:78:27)
at webpack_require (/Users/elliot/reactwork/build/app.node.js:21:30)
at module.exports.Object.defineProperty.value (/Users/elliot/reactwork/build/app.node.js:41:18)
at Object. (/Users/elliot/reactwork/build/app.node.js:42:11)
at Module._compile (module.js:460:26)

Support SCSS @mixin

SCSS @mixin classes are not supported in current build process. I've added support by using sass-loader.

Here is how I resolved the issue:

  1. npm i -D sass-loader
  2. In webpack.config.js, replace all instances of 'postcss-loader' with 'sass-loader'

If there is a better way to achieve this, please let me know.

'npm start' and 'npm run deploy' throwing error

Hey there!

I've downloaded the files and ran 'npm install', but when I run 'npm start' I get this error:

Child
             Asset   Size     Chunks                   Chunk Names
    app.node.js  32 kB              0   [emitted]  main
render
ReferenceError: npm is not defined
    at Object.<anonymous> (/Users/poulosm/Downloads/react-static-boilerplate-master/build/app.node.js:305:3)

I've also tried running 'npm run deploy' and get this error:

deploy
clean
pages
TypeError: Can't call method on  undefined
    at TypeError (<anonymous>)
    at module.exports (/Users/poulosm/Downloads/react-static-boilerplate-master/node_modules/babel-core/node_modules/core-js/modules/$.defined.js:3:28)

--- other tasks ---

Routes Loader Broken?

It appears the tools/lib/routes-loader.js is broken and does correctly generate the / route for any given sub-directory unless it's included in the navigation.js file. Everything but index.html in that same sub-directory is correctly generated and accessible.

To reproduce the issue, using a clean git master checkout, navigate to /blog and you'll get a 404 error. Then navigate to /blog/test-article-one and it works fine.

BTW - The browser reports what I believe is a hot-loader warning in the console when you navigate to /blog or any other / sub-directory not included in navigation.js. Deployed builds do not emit this warning, but still the /blog/index.html fails to load and the 404 page is returned.

Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
 (client) =".13ltol7u1vk.1.0">Not Found</h1><p dat
 (server) =".13ltol7u1vk.1.0">Blog</h1></div></div
warning
_mountImageIntoNode
ReactMount__mountImageIntoNode
mountComponentIntoNode
perform
batchedMountComponentIntoNode
perform
batchedUpdates
batchedUpdates
_renderNewRootComponent
ReactMount__renderNewRootComponent
_renderSubtreeIntoContainer
render
React_render
callee$2$0$
tryCatch
invoke
(anonymous function)
invoke
callInvokeWithMethodAndArg
(anonymous function)
initializePromise
Promise
enqueue
(anonymous function)
async
callee$2$0
route$
tryCatch
invoke
(anonymous function)
invoke
invoke
promiseReactionJob

build/config error

When run npm run build, get error: TypeError: Can't call method on undefined.

After debug the code, I find the reason:

// tools/config.js#L93
const appConfig = merge({}, config, {
  entry: [
    ...(WATCH && ['webpack-hot-middleware/client']),
    './src/js/app.js',
  ],
  // ...
}

when WATCH if falsy(here undefined), ...(undefined) leads to the error.

So, make it like ...(WATCH ? ['webpack-hot-middleware/client'] : []) ?

Integrate postCSS and cssnext

  • Should allow to have CSS per component
  • When React components is mounted, it injects the CSS used in that component, and removes it from DOM right before unmounting

It may looks something like this:

import styles from './MyComponent.css';

@withStyles(styles)
class MyComponent {
  render() { ... }
}

...similarly how it works in React Starter Kit.

Disable server side rendering step

I'm having a bunch of trouble with npm start failing because I'm using d3.csv which depends on XHR, so the pre-render step throws this ReferenceError: XMLHttpRequest is not defined. I've tried a bunch of fixes but I'm no longer sure how much help the pre-rendering really offers, and ready to just give up on it.

What's the best way to disable the server side rendering step, and what are the implications?

building becomes very slow when project gets large

is there any way to improve the building speed?

it takes me 12 seconds on average to build a single small change every time I try to save it.

and if I save twice, it'll build twice and take twice as long to build, so around 24 seconds.

window object not available on server rendering

Hi all ,
while I am using the UI Library : antd , I've got an error like this:

ReferenceError: window is not defined
    at Object.<anonymous> (/Applications/MAMP/htdocs/react/react-static-boilerplate/node_modules/antd/node_modules/velocity-animate/velocity.js:403:4)
    at Module._compile (module.js:425:26)
    at Module._extensions..js (module.js:432:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Applications/MAMP/htdocs/react/react-static-boilerplate/node_modules/babel-core/lib/api/register/node.js:214:7)
    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.<anonymous> (/Applications/MAMP/htdocs/react/react-static-boilerplate/node_modules/antd/node_modules/rc-queue-anim/lib/QueueAnim.js:23:24)
    at Module._compile (module.js:425:26)

I think it is because we rendered the elements on server and there is no window object without a window.
Am I right ? How could I fix it ?
Please help me .
Thanks

Q: how to load "main.css" from the static page?

What is the best practise to load the css bundle (with a hashed filename) in the statically generated pages?

The <Html> component currently does not load any CSS at all, is that expected? Should we be using html-webpack-plugin for this and generate a skeleton template?

Routing doesn't work for github project pages

Html.js and routes-loader.js is set to load files based on root '/'. A github project page is of the format username.github.io/project and root here is username.github.io. The page content and styling doesnt load as the app.js request is going to username.github.io/app.js.

I changed the Html.js script src from "/app.js" to "app.js" and the application loads now, but all pages goes to 404 as the route doesn't match. Whereas it should be username.github.io/project/about, the route is set to username.github.io/about.

This works fine in localhost as about is based on root path (localhost:3000/about). Any idea how to make it work in both localhost as well as the project page? Thanks.

ReferenceError: global not defined

I'm trying to use three.js and so I added a <script> tag referencing a CDN version of it in my Html.js. However, I'm having trouble using the THREE global in my index.js page, like so (paraphrased, so sorry if there's a typo):

export default class extends Component {
  constructor(props) {
    this.state({matrix: new THREE.Matrix3()});
  }

  render() {
    return (
      <div>
        <MyComponent matrix={this.state.matrix} />
      </div>
    );
  }
}

When the render task runs, it gives me a "ReferenceError: THREE is not defined" when running ReactDOM.renderToString for the index page. I'm guessing it's because this is happening before it pulls in the Html component further down in the task, during the ReactDOM.renderToStaticMarkup call.

Any ideas how I can solve this?

How to display a list of blog entries?

Going through my list of must-haves. What will be the best way to show a list of pages in a given directory? i.e. Show a list of all blog entries on the /blog/index.html page.

My thinking is we could somehow include pages and some content in a state object. Thoughts?

--- other tasks ---

babel compatible

Currently when I run npm run clean after npm install, got Error:

/Users/xx/soft/nvm/versions/node/v0.12.6/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/logger.js:41
    throw new Constructor(this._buildMessage(msg));
          ^
ReferenceError: [BABEL] [eval]: Unknown option: /Users/xx/work/projects/react-static-boilerplate/.babelrc.stage
...

It seems that it's an error with babel incompatible. The babel-node used the global installed [email protected], and when I check local node_modules/.bin/ , no babel-node.

Maybe it's required to tell user that globally installed [email protected] will crash tool script. And any plan to support [email protected]?

404 redirect not working

Hi,

I'm trying to test 404 error redirect page, but seems browser sync server is not redircting 404 errors.

for example:
http://localhost:3000/xxx

it returns Cannot GET /xxx in the browser instead of redirecting to /404 page.

anyone know how to redirect?

thanks

Use Kinto as Distributed Database

Hey man,

Love the project! Already learning stuff I didn't know by browsing the source code.

Just an idea, but have you thought of adding kinto as the database? People using github pages for their sites could add a contact form or w/e, without having to create and maintain a server, which is my primary goal.

Just an idea.

Thanks for the great project!

State changes fail on Chrome / Safari with "TypeError: Failed to execute 'replaceChild' on 'Node': parameter 1 is not of type 'Node'."

I'm trying to use a component that has an interactive element to it. This means that given a certain callback (in my case a Firebase value callback) the state of the component is updated.

In Chrome and Safari I get the following error:

Exception was thrown by user callback. TypeError: Failed to execute 'replaceChild' on 'Node': parameter 1 is not of type 'Node'.
    at TypeError (native)
    at Object.Danger.dangerouslyReplaceNodeWithMarkup (eval at <anonymous> (http://localhost:3000/app.js?1451773043685:2808:3), <anonymous>:140:25)
    at Object.ReactDOMIDOperations.dangerouslyReplaceNodeWithMarkupByID (eval at <anonymous> (http://localhost:3000/app.js?1451773043685:1239:3), <anonymous>:71:27)
    at Object.wrapper [as replaceNodeWithMarkupByID] (eval at <anonymous> (http://localhost:3000/app.js?1451773043685:717:3), <anonymous>:66:21)
    at ReactCompositeComponentMixin._replaceNodeWithMarkupByID (eval at <anonymous> (http://localhost:3000/app.js?1451773043685:2862:3), <anonymous>:579:31)
    at ReactCompositeComponentMixin._updateRenderedComponent (eval at <anonymous> (http://localhost:3000/app.js?1451773043685:2862:3), <anonymous>:571:12)
    at ReactCompositeComponentMixin._performComponentUpdate (eval at <anonymous> (http://localhost:3000/app.js?1451773043685:2862:3), <anonymous>:544:10)
    at ReactCompositeComponentMixin.updateComponent (eval at <anonymous> (http://localhost:3000/app.js?1451773043685:2862:3), <anonymous>:473:12)
    at wrapper [as updateComponent] (eval at <anonymous> (http://localhost:3000/app.js?1451773043685:717:3), <anonymous>:66:21)
    at ReactCompositeComponentMixin.performUpdateIfNecessary (eval at <anonymous> (http://localhost:3000/app.js?1451773043685:2862:3), <anonymous>:421:12) 

In Firefox everything works as expected. Am I doing something wrong here? It seems like the component is trying to update an HTML node that is no longer present in the DOM. I can see references to a similar error in the context of triggering onBlur on a node that gets removed, but I don't use onBlur or focussed elements in my code. Shouldn't React take care that an element is always valid? Or is that the dangerous part in dangerouslyReplaceNodeWithMarkup from the call stack?

I skip the Firebase callback for server side rendering, since it doesn't make sense to load real-time data from the database in the static site for this component. When I enable the callback, I get the following error during a npm run build release:

[23:47:48] Starting 'render'...
[23:47:50] Finished 'render' after 1371ms
[23:47:50] Finished 'build' after 16380ms
Warning: React can't find the root component node for data-reactid value `.27bre5ocr28.0.1`. If you're seeing this message, it probably means that you've loaded two copies of React on the page. At this time, only a single copy of React can be loaded at a time.
FIREBASE WARNING: Exception was thrown by user callback. TypeError: Cannot read property 'firstChild' of undefined
    at Object.ReactMount.findComponentRoot (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactMount.js:715:39)
    at Object.ReactMount.findReactNodeByID (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactMount.js:679:23)
    at Object.getNode (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactMount.js:162:32)
    at Object.ReactDOMIDOperations.dangerouslyProcessChildrenUpdates (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactDOMIDOperations.js:83:42)
    at Object.wrapper [as processChildrenUpdates] (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactPerf.js:66:21)
    at processQueue (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactMultiChild.js:160:31)
    at ReactDOMComponent.ReactMultiChild.Mixin.updateChildren (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactMultiChild.js:334:13)
    at ReactDOMComponent.Mixin._updateDOMChildren (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactDOMComponent.js:871:12)
    at ReactDOMComponent.Mixin.updateComponent (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactDOMComponent.js:700:10)
    at ReactDOMComponent.Mixin.receiveComponent (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactDOMComponent.js:645:10)
/Users/kamielwanrooij/Projects/globulr/ui/node_modules/firebase/lib/firebase-node.js:43
ion(){N("Exception was thrown by user callback.",b.stack||"");throw b;},Math.f
                                                                    ^
TypeError: Cannot read property 'firstChild' of undefined
    at Object.ReactMount.findComponentRoot (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactMount.js:715:39)
    at Object.ReactMount.findReactNodeByID (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactMount.js:679:23)
    at Object.getNode (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactMount.js:162:32)
    at Object.ReactDOMIDOperations.dangerouslyProcessChildrenUpdates (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactDOMIDOperations.js:83:42)
    at Object.wrapper [as processChildrenUpdates] (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactPerf.js:66:21)
    at processQueue (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactMultiChild.js:160:31)
    at ReactDOMComponent.ReactMultiChild.Mixin.updateChildren (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactMultiChild.js:334:13)
    at ReactDOMComponent.Mixin._updateDOMChildren (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactDOMComponent.js:871:12)
    at ReactDOMComponent.Mixin.updateComponent (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactDOMComponent.js:700:10)
    at ReactDOMComponent.Mixin.receiveComponent (/Users/kamielwanrooij/Projects/globulr/ui/node_modules/react/lib/ReactDOMComponent.js:645:10)

Which might be related...?

using react-font-awesome in webpack config

I'm trying to using this font-awesome css icons from this github repo.

https://github.com/andreypopp/react-fa

Despite its instructions to use, I'm not entirely sure it's applicable for this static boilerplate I'll be using since the boilerplate comes preconfigured with the css loaders already.

Thus I'm just curious to know how to configure webpack config to import font-awesome? I'm not familiar with webpack environment setup btw vs gulp/grunt.

markup being generated is different on the client or server warning

Running fresh project generated from version 0.2.9, then open http://localhost:3000/blog give warning:

Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
(client) =".23cjq30ov7k.1.0">Not Found<p dat
(server) =".23cjq30ov7k.1.0">Blog<p data-rea

The browser rendering http://localhost:3000/404 instead of the pages/blog/index.js.

Q: Purpose of <Link>?

What is the idea with the <Link> component in the context of a static page generating project? From reading the code I assume its purpose is to intercept clicks and use pushState to manage browsing history, but what is the point of doing that when the final rendered static pages do not use the same mechanism?

<Link> as it stands seem to work poorly with named anchors and mailto: links. Do we really need it?

Build with distinct environment variables?

Is there a way to build with environment specific variables?

e.g. I have a setting API_URL in config.js, and I want that value to change between local development, stage builds, and production builds without exposing the stage API_URL to the production build.

Trying something like process.env doesn't seem to be working. It only compiles into an empty object {}.

Suggestion: Provide critical HTML snippet for the homepage

Much like the critical CSS idea, how about giving first-time visitors the absolutely fastest possible experience by designating a small chunk of HTML + CSS which is sent over the wire first. This reduces transport times, extra CSS loads, page rendering time (especially on long/complex homepages).

The react app then loads everything else, and loads the rest of the content in place. A hook would be needed for a CSS transition (fade in, or something like this).

how can I do wildcard routing

The routes-loader works well until I'm trying to do wildcard routing like this:
/item/:itemID/:itemCategory

any suggestion how to achieve the SEO friendly wildcard routing?

Can not run deploy command

I clone this repository,and can run npm start, but when I run 'npm run deploy' occurs errors:

deploy
clean
pages
TypeError: Can't call method on  undefined
    at TypeError (native)
    at module.exports (/home/yanhua/work/demo/react-static-boilerplate/node_modules/babel-core/node_modules/core-js/modules/$.defined.js:3:63)
    at module.exports (/home/yanhua/work/demo/react-static-boilerplate/node_modules/babel-core/node_modules/core-js/modules/$.to-object.js:4:17)
    at Function.from (/home/yanhua/work/demo/react-static-boilerplate/node_modules/babel-core/node_modules/core-js/modules/es6.array.from.js:12:19)
    at _toConsumableArray (/home/yanhua/work/demo/react-static-boilerplate/tools/config.js:15:178)
    at Object.<anonymous> (/home/yanhua/work/demo/react-static-boilerplate/tools/config.js:89:8)
    at Module._compile (module.js:460:26)
    at normalLoader (/home/yanhua/work/demo/react-static-boilerplate/node_modules/babel-core/lib/api/register/node.js:199:5)
    at Object.require.extensions.(anonymous function) [as .js] (/home/yanhua/work/demo/react-static-boilerplate/node_modules/babel-core/lib/api/register/node.js:216:7)
    at Module.load (module.js:355:32)

I use Ubuntu and node0.12.4, Thanks.

--- other tasks ---

`static propTypes` causing Unexpected Token errors out of the box

After running npm install and npm start, there's multiple Unexpected token errors that look like this:

    Module build failed: SyntaxError: /Users/cassidoo/GitHub/hub/pages/500.js: Unexpected token (11:19)
       9 | export default class extends Component {
      10 |
    > 11 |   static propTypes = {

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.