Skip to content

Commit

Permalink
switch to web pack dev server for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanflorence committed Nov 10, 2014
1 parent 5497538 commit 31c160d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 15 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ always be in sync.

### Development

- `script/test` will fire up a karma runner and watch for changes in the
specs directory.
- `npm test` will do the same but doesn't watch, just runs the tests.
- `script/build-examples` does exactly that.
- `npm start` runs the dev server to run/develop examples
- `npm test` will run the test.
- `script/test` same as `npm test` but keeps karma running and watches
for changes

### Build

Expand Down
5 changes: 3 additions & 2 deletions examples/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<link href="app.css" rel="stylesheet"/>
<body>
<div id="example"></div>
<script src="../global-bundle.js"></script>
<script src="app-bundle.js"></script>
<script src="/__build__/shared.js"></script>
<script src="/__build__/basic.js"></script>

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"example": "examples"
},
"scripts": {
"test": "script/test --browsers Firefox --single-run"
"test": "script/test --browsers Firefox --single-run",
"start": "script/dev-examples"
},
"authors": [
"Ryan Florence"
Expand All @@ -24,6 +25,7 @@
"browserify-shim": "3.6.0",
"envify": "1.2.0",
"expect": "0.1.1",
"jsx-loader": "0.11.2",
"karma": "0.12.16",
"karma-browserify": "^0.2.1",
"karma-chrome-launcher": "0.1.4",
Expand All @@ -35,7 +37,8 @@
"react-tap-event-plugin": "git://github.com/appsforartists/react-tap-event-plugin",
"reactify": "^0.14.0",
"rf-release": "0.3.1",
"uglify-js": "2.4.15"
"uglify-js": "2.4.15",
"webpack-dev-server": "1.6.5"
},
"peerDependencies": {
"react": ">=0.11.0"
Expand All @@ -55,4 +58,4 @@
"browserify-shim": {
"react": "global:React"
}
}
}
6 changes: 0 additions & 6 deletions script/build-examples

This file was deleted.

3 changes: 3 additions & 0 deletions script/dev-examples
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
node_modules/.bin/webpack-dev-server --inline --content-base examples/

52 changes: 52 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var fs = require('fs');
var path = require('path');
var webpack = require('webpack');

var EXAMPLES_DIR = path.resolve(__dirname, 'examples');

function isDirectory(dir) {
return fs.lstatSync(dir).isDirectory();
}

function buildEntries() {
return fs.readdirSync(EXAMPLES_DIR).reduce(function (entries, dir) {
if (dir === 'build')
return entries;

var isDraft = dir.charAt(0) === '_';

if (!isDraft && isDirectory(path.join(EXAMPLES_DIR, dir)))
entries[dir] = path.join(EXAMPLES_DIR, dir, 'app.js');

return entries;
}, {});
}

module.exports = {

entry: buildEntries(),

output: {
filename: '[name].js',
chunkFilename: '[id].chunk.js',
path: 'examples/__build__',
publicPath: '/__build__/'
},

module: {
loaders: [
{ test: /\.js$/, loader: 'jsx-loader?harmony' }
]
},

resolve: {
alias: {
'react-router': '../../modules/index'
}
},

plugins: [
new webpack.optimize.CommonsChunkPlugin('shared.js')
]

};

0 comments on commit 31c160d

Please sign in to comment.