commit b9e6653ceed0e9c344377da5eb367578a801dcad parent 133f30b5e15f3ee6f574ed75ea440600f0862732 Author: Konstantin Tarkus <koistya@gmail.com> Date: Tue, 16 Jun 2015 12:55:36 +0300 Merge pull request #142 from koistya/public-assets Compile public assets into the /build/public folder Diffstat:
13 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/README.md b/README.md @@ -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 diff --git a/docs/recipes/how-to-implement-routing.md b/docs/recipes/how-to-implement-routing.md @@ -80,7 +80,7 @@ async function render() { } catch (err) { React.render(<ErrorPage {...err} />, container); } -}; +} window.addEventListener('hashchange', () => render()); render(); @@ -128,7 +128,7 @@ async function render() { } catch (err) { React.render(<ErrorPage {...err} />, container); } -}; +} window.addEventListener('hashchange', () => render()); render(); diff --git a/gulpfile.babel.js b/gulpfile.babel.js @@ -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 @@ -65,7 +73,7 @@ gulp.task('bundle', cb => { cachedAssets: verbose })); - if (++bundlerRunCount === config.length) { + if (++bundlerRunCount === (watch ? config.length : 1)) { return cb(); } } @@ -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(); }); }); diff --git a/src/assets/apple-touch-icon.png b/src/public/apple-touch-icon.png Binary files differ. diff --git a/src/assets/browserconfig.xml b/src/public/browserconfig.xml diff --git a/src/assets/crossdomain.xml b/src/public/crossdomain.xml diff --git a/src/assets/favicon.ico b/src/public/favicon.ico Binary files differ. diff --git a/src/assets/humans.txt b/src/public/humans.txt diff --git a/src/assets/robots.txt b/src/public/robots.txt diff --git a/src/assets/tile-wide.png b/src/public/tile-wide.png Binary files differ. diff --git a/src/assets/tile.png b/src/public/tile.png Binary files differ. diff --git a/src/server.js b/src/server.js @@ -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 diff --git a/webpack.config.js b/webpack.config.js @@ -37,7 +37,6 @@ const GLOBALS = { const config = { output: { - path: './build/', publicPath: './', sourcePrefix: ' ' }, @@ -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, @@ -130,6 +130,7 @@ const appConfig = merge({}, config, { const serverConfig = merge({}, config, { entry: './src/server.js', output: { + path: './build', filename: 'server.js', libraryTarget: 'commonjs2' },