Skip to content
This repository has been archived by the owner on Aug 30, 2018. It is now read-only.

Commit

Permalink
[fix] update production build and add cache-busting
Browse files Browse the repository at this point in the history
  • Loading branch information
m4dz committed Oct 26, 2016
1 parent 628e4c7 commit c066b61
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -65,7 +65,6 @@
"test:server": "sh scripts/tests.sh",
"lint": "sh scripts/lint.sh",
"start": "node build/server.js",
"prebuild": "cd client && npm install",
"watch": "npm-run-all --parallel 'watch:*'",
"watch:client": "cd client && webpack --display-modules --display-chunks --watch",
"watch:server": "coffee server.coffee"
Expand Down
26 changes: 16 additions & 10 deletions scripts/build.sh
@@ -1,32 +1,38 @@
#!/usr/bin/env bash

export PATH="./node_modules/.bin:$PATH"
export OPTIMIZE=true


echo "Clean previous server"
rm -rf build/server && mkdir -p build/server
echo "Previous server cleaned."

echo "Build server files..."
./node_modules/.bin/coffee -cb --output build/server server
./node_modules/.bin/coffee -cb --output build/ server.coffee
./node_modules/.bin/babel ./server/konnectors -d build/server/konnectors
./node_modules/.bin/babel ./server/lib -d build/server/lib
coffee -cb --output build/server server
coffee -cb --output build/ server.coffee
babel ./server/konnectors -d build/server/konnectors
babel ./server/lib -d build/server/lib
echo "Server built."

echo "Clean previous client build..."
rm -rf build/client && mkdir -p build/client/app
echo "Previous client cleaned."

echo "Build entry point..."
./node_modules/.bin/jade ./client/index.jade -c --out ./build/client/
mkdir -p ./build/server/views
jade --client --no-debug --hierarchy --out ./build/server ./server
echo "var jade = require('jade/runtime');module.exports=" | \
cat - ./build/client/index.js > ./build/client/index.js.tmp
mv ./build/client/index.js.tmp ./build/client/index.js
cat - ./build/server/views/index.js > ./build/server/views/index.js.tmp
mv ./build/server/views/index.js.tmp ./build/server/views/index.js
echo "Entry point built."

echo "Build locales..."
./node_modules/.bin/coffee -cb --output build/client/app/locales ./client/app/locales
cp -r ./client/app/locales ./build/client/app/
echo "Locales built."

echo "Build client..."
cd client/ && npm i && ./node_modules/.bin/brunch build --production && cd ..
cp -R client/public build/client/
cd ./client
npm install
webpack
echo "Client built."
9 changes: 8 additions & 1 deletion server.coffee
Expand Up @@ -31,7 +31,14 @@ application = module.exports = (callback) ->
log.info 'Import poller started.'
callback(app, server) if callback?

# Try to get assets definitions from root
# (only valid in build, not on watch mode)
try
hash = ".#{require('./assets').hash}"
catch
hash = ''
app.locals.hash = hash


if not module.parent
application()

6 changes: 3 additions & 3 deletions server/views/index.jade
Expand Up @@ -7,8 +7,8 @@ html(lang="en")
title Cozy - Konnectors

link(rel="stylesheet" href="/fonts/fonts.css")
link(rel="stylesheet" href="app.css")

script(src="app.js" defer=true)
link(rel="stylesheet" href="app#{hash}.css")

script(src="app#{hash}.js" defer=true)

div(role="application")

0 comments on commit c066b61

Please sign in to comment.