Skip to content

Commit

Permalink
Building the static assets
Browse files Browse the repository at this point in the history
  • Loading branch information
pirelenito committed Nov 8, 2015
1 parent da0a30c commit 0e7f9dc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
npm-debug.log
npm-debug.log
dist
15 changes: 15 additions & 0 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node

require('babel/register')

var staticAssets = require('../server/static-assets')

staticAssets.build(function (err) {
if (err) {
console.log('Build failed')
console.log(arguments)
process.exit(1)
}

console.log('Build success!')
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"start": "node bin/server.js",
"test": "standard",
"dev": "supervisor --watch server bin/server.js",
"build": "node bin/build.js",
"deploy": "modulus deploy"
},
"repository": {
Expand Down
11 changes: 9 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import staticAssets from './static-assets'

var express = require('express')
var http = require('http')
var app = express()
Expand All @@ -7,17 +9,22 @@ var session = require('express-session')({
resave: false,
saveUninitialized: true
})

var sharedsession = require('express-socket.io-session')
var SocketIO = require('socket.io')
var io = new SocketIO(server, { path: '/game-socket' })

// app.use(express.static('./client'))

if (process.env.NODE_ENV === 'production') {
app.use(express.static('./dist'))
} else {
staticAssets(app)
}

app.use(session)
io.use(sharedsession(session))

require('./maps')
require('./static-assets')(app)
require('./routes')(app, io)

export default server
7 changes: 6 additions & 1 deletion server/static-assets/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import express from 'express'
import webpack from 'webpack'
import webpackConfig from './webpack-config'

Expand All @@ -13,3 +12,9 @@ export default function (app) {

app.use(require('webpack-hot-middleware')(compiler))
}


export function build (cb) {
const compiler = webpack(webpackConfig)
compiler.run(cb)
}
30 changes: 20 additions & 10 deletions server/static-assets/webpack-config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import path from 'path'
import { HotModuleReplacementPlugin } from 'webpack'
import { HotModuleReplacementPlugin, optimize } from 'webpack'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import reactTransform from 'babel-plugin-react-transform'
import { join } from 'path'

const projectPath = join(__dirname, '../../')
const watch = true
const watch = process.env.NODE_ENV !== 'production'


const plugins = []
if (watch) {
plugins.push(
new HtmlWebpackPlugin({ template: 'client/index.html' }),
new HotModuleReplacementPlugin())
} else {
plugins.push(new optimize.UglifyJsPlugin())
}


const entry = ['./index']
if (watch) {
entry.push('webpack-hot-middleware/client')
}


export default {
Expand All @@ -16,10 +32,7 @@ export default {
failOnError: !watch
},

entry: [
'webpack-hot-middleware/client',
'./index'
],
entry,

resolve: {
root: [
Expand All @@ -32,10 +45,7 @@ export default {
filename: 'index.js'
},

plugins: [
new HtmlWebpackPlugin({ template: 'client/index.html' }),
new HotModuleReplacementPlugin()
],
plugins,

babel: {
optional: ['runtime'],
Expand Down

0 comments on commit 0e7f9dc

Please sign in to comment.