Code Monkey home page Code Monkey logo

react-webpack-php-starter's Introduction

react-webpack-php-starter

This is a boilerplate React application that I use to start new projects. It uses webpack to build the JavaScript bundle file and PHP for the back-end API. Inspired by Christian Alfoni's ultimate webpack setup.

Overview

React apps are often served using a node server like Express. However, in my case I wanted to use Apache because we use PHP to manage user authentication. I know there are packages that theoretically can make Express serve PHP, but it was easier to just use our existing Apache server.

This happens to be my specific use case at the moment, but this project could easily be adapted to use a node server instead.

Goals

I wanted a setup that would enable the following features:

  • Bundling and minification using webpack
  • ECMAScript 2015 (ES6) syntax via Babel
  • Linting
  • Separate builds for development and production
  • Bootstrap styles
  • SVG icons
  • PHP index file and back-end API
  • Automatic browser reloading using Browsersync

Directory Structure

The project is structured like this:

  • /public (web root)
    • /api (back-end API in PHP)
    • /build (built code)
    • index.php
  • /src (source code that needs to go through the build process)
    • /components (React components)
    • /css
    • /svg
    • constants.js (application-wide variables)
    • history.js (browser history as separate module)
    • main.js (the webpack entry file)
  • .gitignore
  • package.json
  • README.md
  • webpack-production.config.js
  • webpack-config.js

The public directory is the web root. Configure the server to serve files from there. The build directory is where the webpack output files go. This directory is ignored by git.

Builds

The "scripts" section of the package.json file contains the build scripts. When you first checkout the project you'll need to run npm install to get all the node modules used.

For development type:

npm start

The development build runs webpack in watch mode. Whenever you save changes to a file in the src folder it rebuilds the bundle.

For production type:

npm run build

The production build deletes the build folder and rebuilds the bundle using the settings in webpack-production.config.js. Code gets minified and console logs get stripped out.

react-webpack-php-starter's People

Contributors

mnvx avatar brawlins avatar

Watchers

 avatar

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.