An opinionated webpack config for GitHub apps.
Перейти к файлу
Kristján Oddsson cd56f9465d
0.13.0
2019-01-31 17:23:37 +00:00
examples update @types/relay-runtime to latest version in test 2019-01-29 12:09:43 +00:00
.eslintignore ignore all node_modules folders 2018-12-11 14:35:32 +00:00
.eslintrc.json Change lint rules for examples 2017-11-15 21:59:26 -08:00
.flowconfig Add basic flow types 2017-11-15 18:35:27 -08:00
.gitignore ignore all node_modules in git 2018-12-11 14:58:32 +00:00
.prettierignore Don't pretty package.json, npm does that 2018-09-12 13:27:05 -07:00
.travis.yml Add Travis CI config 2017-11-17 10:31:31 -08:00
LICENSE Add LICENSE 2017-11-16 00:02:27 -08:00
README.md Add basic HTML minfiication 2017-12-04 15:53:18 -08:00
index.html Remove 'Webpack' title 2018-01-05 14:36:28 -08:00
package.json 0.13.0 2019-01-31 17:23:37 +00:00
prettier.config.js make all file flow strict 2018-10-12 15:32:27 +01:00
test.sh only run a single test if argument is passed to script 2018-12-10 13:48:00 +00:00
webpack-docker-server.js make all file flow strict 2018-10-12 15:32:27 +01:00
webpack.config.js user terser instead of babel to minify 2019-01-24 14:59:37 +00:00

README.md

webpack-config-github

An opinionated webpack config for GitHub apps.

Features

  • Single and multiple HTML entry points
  • Common chunks bundle when using multiple entry points
  • ES6 transpilation via Babel
  • Source Maps
  • PostCSS
  • HTML5 History routing (in development)
  • GraphQL proxy (in development)
  • Content Security Policy
  • HTML and JS minification (in production)
  • Static gzip compression (in production)
  • Docker nginx deployment

Deployment

Currently targets the Docker nginx deployment environment. Improved gh-pages deployment is planned in the future.

Basic Setup

$ npm install --save-dev webpack-dev-server
$ npm install --save-dev webpack-config-github

webpack.config.js

module.exports = require('webpack-config-github')

src/index.js

document.body.innerHTML = '<h1>Hello, World!</h1>'

Start development server

$ webpack-dev-server --open

Directory Structure

my-app
├── package.json
├── Dockerfile
├── config
│   └── nginx.conf
├── .graphqlconfig
├── data
│   └── schema.graphql
├── node_modules
├── public
│   └── favicon.ico
│   └── robots.txt
└── src
    └── index.js
    └── components
        └── App.js
        └── Layout.js
        └── Sidebar.js

Dockerfile

The currently suggested deployment target is the Docker nginx image.

See the example Dockerfile.

config/nginx.conf

This example nginx.conf aligns the static serving with the webpack-dev-server.

.graphqlconfig

Specifies the location of the GraphQL schema and target endpoints.

Here is an example configuration file when targeting the GitHub GraphQL API.

{
  "schemaPath": "data/schema.graphql",
  "extensions": {
    "endpoints": {
      "production": {
        "url": "https://api.github.com/graphql",
        "headers": {
          "Authorization": "Bearer ${env:API_TOKEN}"
        }
      }
    }
  }
}

See the GraphQL Configuration Format for more information.

data/schema.graphql

When using Relay, a copy of the GraphQL schema should be checked in at this location. Checking the schema in ensures linting and build tools can be consistently ran offline and in CI.

public/

The public/ directory contains static assets that will be exposed as is. This is useful for well known static assets that need to be served at a specific root path like favicon.ico and robots.txt.

src/

Contains source JavaScript, CSS and other assets that will be compiled via webpack.

src/index.js

Is the main entry point for bootstrapping the application.

When using React, this file should render the root application component.

import React from 'react'
import ReactDOM from 'react-dom'

import App from './components/App'

ReactDOM.render(<App />, document.getElementById('root'))

Roadmap

  • Add Subresource Integrity support
  • Support CSS Modules
  • Support hot reloading
  • Add gh-pages deployment pattern

See Also

Many of the directory conventions used here are inspired from create-react-app.