Skip to content

Commit

Permalink
Compile public assets into the /build/public folder
Browse files Browse the repository at this point in the history
  • Loading branch information
koistya committed Jun 16, 2015
1 parent 133f30b commit 8fefb22
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
├── /src/ # The source code of the application
│ ├── /api/ # REST API / Relay endpoints
│ ├── /actions/ # Action creators that allow to trigger a dispatch to stores
│ ├── /assets/ # Static files which are copied to ./build on compile
│ ├── /components/ # React components
│ ├── /constants/ # Constants (action types etc.)
│ ├── /content/ # Static content (plain HTML or Markdown, Jade, you name it)
│ ├── /core/ # Core components (Flux dispatcher, base classes, utilities)
│ ├── /decorators/ # Higher-order React components
│ ├── /public/ # Static files which are copied into the /build/public folder
│ ├── /stores/ # Stores contain the application state and logic
│ ├── /templates/ # HTML templates for server-side rendering, emails etc.
│ ├── /utils/ # Utility classes and functions
Expand Down
4 changes: 2 additions & 2 deletions docs/recipes/how-to-implement-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function render() {
} catch (err) {
React.render(<ErrorPage {...err} />, container);
}
};
}

window.addEventListener('hashchange', () => render());
render();
Expand Down Expand Up @@ -128,7 +128,7 @@ async function render() {
} catch (err) {
React.render(<ErrorPage {...err} />, container);
}
};
}

window.addEventListener('hashchange', () => render());
render();
Expand Down
27 changes: 19 additions & 8 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,24 @@ gulp.task('clean', () => del(['.tmp', 'build/*', '!build/.git'], {dot: true}));

// Static files
gulp.task('assets', () => {
src.assets = [
src.assets = 'src/public/**';
return gulp.src(src.assets)
.pipe($.changed('build/public'))
.pipe(gulp.dest('build/public'))
.pipe($.size({title: 'assets'}));
});

// Resource files
gulp.task('resources', () => {
src.resources = [
'package.json',
'src/assets/**',
'src/content*/**/*.*',
'src/templates*/**/*.*'
'src/content*/**',
'src/templates*/**'
];
return gulp.src(src.assets)
return gulp.src(src.resources)
.pipe($.changed('build'))
.pipe(gulp.dest('build'))
.pipe($.size({title: 'assets'}));
.pipe($.size({title: 'resources'}));
});

// Bundle
Expand All @@ -65,7 +73,7 @@ gulp.task('bundle', cb => {
cachedAssets: verbose
}));

if (++bundlerRunCount === config.length) {
if (++bundlerRunCount === (watch ? config.length : 1)) {
return cb();
}
}
Expand All @@ -78,13 +86,16 @@ gulp.task('bundle', cb => {
});

// Build the app from source code
gulp.task('build', ['clean'], cb => { runSequence(['assets', 'bundle'], cb); });
gulp.task('build', ['clean'], cb => {
runSequence(['assets', 'resources'], ['bundle'], cb);
});

// Build and start watching for modifications
gulp.task('build:watch', cb => {
watch = true;
runSequence('build', () => {
gulp.watch(src.assets, ['assets']);
gulp.watch(src.resources, ['resources']);
cb();
});
});
Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import App from './components/App';
const server = express();

server.set('port', (process.env.PORT || 5000));
server.use(express.static(path.join(__dirname)));
server.use(express.static(path.join(__dirname, 'public')));

//
// Register API middleware
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const GLOBALS = {

const config = {
output: {
path: './build/',
publicPath: './',
sourcePrefix: ' '
},
Expand Down Expand Up @@ -110,6 +109,7 @@ const config = {
const appConfig = merge({}, config, {
entry: './src/app.js',
output: {
path: './build/public',
filename: 'app.js'
},
devtool: DEBUG ? 'source-map' : false,
Expand All @@ -130,6 +130,7 @@ const appConfig = merge({}, config, {
const serverConfig = merge({}, config, {
entry: './src/server.js',
output: {
path: './build',
filename: 'server.js',
libraryTarget: 'commonjs2'
},
Expand Down

0 comments on commit 8fefb22

Please sign in to comment.