Skip to content

Commit 3e37e10

Browse files
author
Mat Brown
committed
Serve all static assets from the same root directory
Previously assets were served from the `static/` directory; at the root of this directory were unmodified static files that were part of version control, e.g. `index.html`. This contained `static/compiled/`, which contained compiled files (CSS bundle, JS bundle, etc.) and was not under version control. Now all assets are served from the `dist` directory in the root of the project; `static` has moved to `src/static`. The proximate motivation for this is that service workers can’t control files outside of the directory they are served from; so, serving a service worker from `/compiled/sw.js` prevented that service worker from caching `/index.html`. This can be overridden with a header, but since we serve the site statically from S3, that’s not so simple. This change also I think is strictly more sensible.
1 parent 63d9bef commit 3e37e10

19 files changed

Lines changed: 42 additions & 31 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
static/compiled
1+
dist
22
node_modules
33
npm-debug.log
44
bower_components

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ deploy:
3838
secure: qqkSdpnlOM80HavspUc/S4OpohDAkbDqaCKQTw08j2/CaU0LwN335CVQhDZ4Oskgr6y5evx6LrTU0BNiDfzcMIEykokV1ZCPLuWLrHo/ZtCSIU+3ikVErY/0qZH4FdZ1h/Q1FP5gTDydP0QbXWkQsQQg1cgg2NTX4/BsTTT9nBRJeg4Gdm9ARLW0b3SGutW13tW8fuRG9YrNJs6gKZsZ6FhP1ru4T47tdsbphV1IsedZv8nU7dGnWQj67//4OpAHOi1KOm6K1CprNa35Kw7D/+n6786skbPi7Tsu7UbIVMWD+Jy1c2xtz3mqinIbyS8spzLd3kbDV+BRvIYXXHpC6B4gGhyRd+ohN+WcoDQZJha2PaOfIPfAxPhK2IKO6h+6i8Q0CK4/x4Yd8PurVHrB8KEyPrMHPa42abMTTeRLs7OAjrtM7dWucngCvW6fBqhpgp36cRDZeXLKjywkapo1/6l64fjkM+wGkYFkI5i6qzEAr0JvBrIeTDiymz1Oitf3Uio+vs4hfjXegQansq5l/mXtMdI9DfNrKm/R2zpUp1qS7i+v1MfnhAxd8NOEGYpT75sJbSVca0jgnkLXcja6+O4oRswx4maA+BTiIcwknAn6B4Rupf8U0Tnt3s/pFu6Ih6lnMo6rpeBkV7FO1Bwyv59zyxZS8Z23ec+v7+TZ/iE=
3939
bucket: popcode.org
4040
skip_cleanup: true
41-
local-dir: static
41+
local-dir: dist
4242
acl: public_read
4343
on:
4444
repo: popcodeorg/popcode

gulpfile.js

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/* eslint-disable import/no-nodejs-modules */
66

77
const fs = require('fs');
8+
const path = require('path');
89
const https = require('https');
910
const gulp = require('gulp');
1011
const yargs = require('yargs');
@@ -26,9 +27,9 @@ const webpackConfiguration = require('./webpack.config');
2627

2728
const browserSync = BrowserSync.create();
2829
const srcDir = 'src';
29-
const baseDir = 'static';
30-
const distDir = `${baseDir}/compiled`;
31-
const stylesheetsDir = `${srcDir}/css`;
30+
const distDir = 'dist';
31+
const stylesheetsDir = path.join(srcDir, 'css');
32+
const staticDir = path.join(srcDir, 'static');
3233
const bowerComponents = 'bower_components';
3334

3435
const cssnextBrowsers = [];
@@ -49,14 +50,24 @@ gulp.task('env', () => {
4950
}
5051
});
5152

53+
gulp.task('static', () => gulp.
54+
src(path.join(staticDir, '**/*')).
55+
pipe(gulp.dest(distDir))
56+
);
57+
5258
gulp.task('fonts', () => gulp.
5359
src([
54-
`${bowerComponents}/inconsolata-webfont/fonts/inconsolata-regular.*`,
55-
`${bowerComponents}/fontawesome/fonts/fontawesome-webfont.*`,
56-
`${bowerComponents}/roboto-webfont-bower/fonts/` +
57-
'Roboto-{Bold,Regular}-webfont.*',
60+
path.join(
61+
bowerComponents,
62+
'inconsolata-webfont/fonts/inconsolata-regular.*'
63+
),
64+
path.join(bowerComponents, 'fontawesome/fonts/fontawesome-webfont.*'),
65+
path.join(
66+
bowerComponents,
67+
'roboto-webfont-bower/fonts/Roboto-{Bold,Regular}-webfont.*'
68+
),
5869
]).
59-
pipe(gulp.dest(`${distDir}/fonts`))
70+
pipe(gulp.dest(path.join(distDir, 'fonts')))
6071
);
6172

6273
gulp.task('css', () => {
@@ -67,8 +78,8 @@ gulp.task('css', () => {
6778

6879
return gulp.
6980
src([
70-
`${bowerComponents}/normalize-css/normalize.css`,
71-
`${stylesheetsDir}/**/*.css`,
81+
path.join(bowerComponents, 'normalize-css/normalize.css'),
82+
path.join(stylesheetsDir, '**/*.css'),
7283
]).
7384
pipe(concat('application.css')).
7485
pipe(sourcemaps.init({loadMaps: true})).
@@ -92,11 +103,12 @@ gulp.task('js', ['env'], () => {
92103
return pify(webpack)(productionWebpackConfig);
93104
});
94105

95-
gulp.task('build', ['fonts', 'css', 'js']);
106+
gulp.task('build', ['static', 'fonts', 'css', 'js']);
96107

97108
gulp.task('syncFirebase', async () => {
98-
const data =
99-
await pify(fs).readFile(`${__dirname}/config/firebase-auth.json`);
109+
const data = await pify(fs).readFile(
110+
path.resolve(__dirname, 'config/firebase-auth.json')
111+
);
100112
const firebaseSecret = process.env.FIREBASE_SECRET;
101113
if (!firebaseSecret) {
102114
throw new Error('Missing environment variable FIREBASE_SECRET');
@@ -120,23 +132,23 @@ gulp.task('syncFirebase', async () => {
120132
});
121133
});
122134

123-
gulp.task('dev', ['browserSync', 'fonts', 'css'], () => {
124-
gulp.watch(`${stylesheetsDir}/**/*.css`, ['css']);
125-
gulp.watch(`${baseDir}/*`).on('change', browserSync.reload);
135+
gulp.task('dev', ['browserSync', 'static', 'fonts', 'css'], () => {
136+
gulp.watch(path.join(staticDir, '/**/*'), ['static']);
137+
gulp.watch(path.join(stylesheetsDir, '**/*.css'), ['css']);
138+
gulp.watch(path.join(distDir, '*')).on('change', browserSync.reload);
126139
});
127140

128-
gulp.task('browserSync', () => {
141+
gulp.task('browserSync', ['static'], () => {
129142
const compiler = webpack(webpackConfiguration);
130143
compiler.plugin('invalid', browserSync.reload);
131144
browserSync.init({
132145
server: {
133-
baseDir,
146+
baseDir: distDir,
134147
middleware: [webpackDevMiddleware(
135148
compiler,
136149
{
137150
lazy: false,
138151
stats: 'errors-only',
139-
publicPath: `/${webpackConfiguration.output.publicPath}`,
140152
}
141153
)],
142154
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
"lint": "eslint --ext .js,.jsx --plugin react src test && stylelint src/**/*.css",
150150
"fixlint": "eslint --ext .js,.jsx --plugin react --fix src test",
151151
"toc": "doctoc README.md --github --title '## Table of Contents'",
152-
"preview": "rm -rvf static/compiled && gulp build --production && static static"
152+
"preview": "rm -rvf dist && gulp build --production && static dist"
153153
},
154154
"devDependencies": {
155155
"babel-cli": "^6.23.0",

src/components/Pop.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import Neutral from '../../static/images/pop/neutral.svg';
4-
import Thinking from '../../static/images/pop/thinking.svg';
5-
import Horns from '../../static/images/pop/horns.svg';
3+
import Neutral from '../static/images/pop/neutral.svg';
4+
import Thinking from '../static/images/pop/thinking.svg';
5+
import Horns from '../static/images/pop/horns.svg';
66

77
const variants = {
88
neutral: Neutral,

src/components/Sidebar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import {t} from 'i18next';
44
import classnames from 'classnames';
55
import partial from 'lodash/partial';
6-
import WordmarkVertical from '../../static/images/wordmark-vertical.svg';
6+
import WordmarkVertical from '../static/images/wordmark-vertical.svg';
77

88
class Sidebar extends React.Component {
99
_renderHiddenComponents() {

src/css/application.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ body {
625625
}
626626

627627
.pop-throbber__image {
628-
background: url('../images/pop/thinking.svg') center no-repeat;
628+
background: url('./images/pop/thinking.svg') center no-repeat;
629629
height: 100%;
630630
}
631631

0 commit comments

Comments
 (0)