Skip to content

Commit b98f5a1

Browse files
committed
[changed] Use webpack instead of Browserify
Closes #625 Closes #608
1 parent b9dbce7 commit b98f5a1

File tree

8 files changed

+101
-93
lines changed

8 files changed

+101
-93
lines changed

CONTRIBUTING.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ always be in sync.
3434

3535
### Development
3636

37-
- `scripts/test` will fire up a karma runner and watch for changes in the
38-
specs directory.
39-
- `npm test` will do the same but doesn't watch, just runs the tests.
37+
- `npm test` will fire up a karma test runner and watch for changes
4038
- `npm run examples` fires up a webpack dev server that will watch
41-
for changes and build the examples.
39+
for changes and build the examples
4240

4341
### Build
4442

examples/webpack.config.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var fs = require('fs');
2+
var path = require('path');
3+
var webpack = require('webpack');
4+
5+
function isDirectory(dir) {
6+
return fs.lstatSync(dir).isDirectory();
7+
}
8+
9+
module.exports = {
10+
11+
devtool: 'inline-source-map',
12+
13+
entry: fs.readdirSync(__dirname).reduce(function (entries, dir) {
14+
var isDraft = dir.charAt(0) === '_';
15+
16+
if (!isDraft && isDirectory(path.join(__dirname, dir)))
17+
entries[dir] = path.join(__dirname, dir, 'app.js');
18+
19+
return entries;
20+
}, {}),
21+
22+
output: {
23+
path: 'examples/__build__',
24+
filename: '[name].js',
25+
chunkFilename: '[id].chunk.js',
26+
publicPath: '/__build__/'
27+
},
28+
29+
module: {
30+
loaders: [
31+
{ test: /\.js$/, loader: 'jsx-loader?harmony' }
32+
]
33+
},
34+
35+
resolve: {
36+
alias: {
37+
'react-router': '../../modules'
38+
}
39+
},
40+
41+
plugins: [
42+
new webpack.optimize.CommonsChunkPlugin('shared.js'),
43+
new webpack.DefinePlugin({
44+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
45+
})
46+
]
47+
48+
};

karma.conf.js

+22-24
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
1+
var webpack = require('webpack');
2+
13
module.exports = function (config) {
24
config.set({
35

4-
basePath: '',
6+
browsers: [ process.env.CONTINUOUS_INTEGRATION ? 'Firefox' : 'Chrome' ],
7+
8+
singleRun: process.env.CONTINUOUS_INTEGRATION === 'true',
59

6-
frameworks: [ 'mocha', 'browserify' ],
10+
frameworks: [ 'mocha' ],
711

812
files: [
9-
'modules/**/__tests__/*-test.js'
13+
'tests.webpack.js'
1014
],
1115

1216
preprocessors: {
13-
'modules/**/__tests__/*-test.js': [ 'browserify' ]
17+
'tests.webpack.js': [ 'webpack', 'sourcemap' ]
1418
},
1519

16-
browserify: {
17-
debug: true,
18-
watch: true,
19-
transform: [
20-
[ 'reactify', { 'es6': true } ],
21-
'envify'
20+
webpack: {
21+
devtool: 'inline-source-map',
22+
module: {
23+
loaders: [
24+
{ test: /\.js$/, loader: 'jsx-loader?harmony' }
25+
]
26+
},
27+
plugins: [
28+
new webpack.DefinePlugin({
29+
'process.env.NODE_ENV': JSON.stringify('test')
30+
})
2231
]
2332
},
2433

25-
reporters: [ 'progress' ],
26-
27-
port: 9876,
28-
29-
colors: true,
30-
31-
logLevel: config.LOG_INFO,
32-
33-
autoWatch: true,
34-
35-
browsers: [ 'Chrome' ],
36-
37-
captureTimeout: 60000,
34+
webpackServer: {
35+
noInfo: true
36+
}
3837

39-
singleRun: false
4038
});
4139
};

package.json

+19-25
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,36 @@
1313
"example": "examples"
1414
},
1515
"scripts": {
16-
"examples": "webpack-dev-server --inline --no-info --content-base examples",
17-
"test": "scripts/test --browsers Firefox --single-run",
18-
"lint": "jsxhint examples modules"
19-
16+
"build": "webpack modules/index.js dist/react-router.js",
17+
"build-min": "uglifyjs dist/react-router.js --compress warnings=false > dist/react-router.min.js",
18+
"examples": "webpack-dev-server --config examples/webpack.config.js --no-info --content-base examples",
19+
"test": "jsxhint . && karma start"
2020
},
2121
"authors": [
2222
"Ryan Florence",
2323
"Michael Jackson"
2424
],
2525
"license": "MIT",
2626
"devDependencies": {
27-
"browserify": "4.2.3",
28-
"browserify-shim": "3.6.0",
29-
"bundle-loader": "0.5.1",
30-
"envify": "1.2.0",
27+
"bundle-loader": "^0.5.2",
3128
"events": "1.0.2",
32-
"expect": "0.1.1",
33-
"jsx-loader": "0.12.0",
29+
"expect": "^1.1.0",
30+
"jsx-loader": "^0.12.2",
3431
"jsxhint": "^0.8.1",
35-
"karma": "0.12.16",
36-
"karma-browserify": "1.0.0",
37-
"karma-chrome-launcher": "0.1.4",
32+
"karma": "^0.12.28",
33+
"karma-chrome-launcher": "^0.1.7",
3834
"karma-cli": "0.0.4",
39-
"karma-firefox-launcher": "0.1.3",
40-
"karma-mocha": "0.1.3",
41-
"mocha": "1.20.1",
35+
"karma-firefox-launcher": "^0.1.3",
36+
"karma-mocha": "^0.1.10",
37+
"karma-sourcemap-loader": "^0.3.2",
38+
"karma-webpack": "^1.3.1",
39+
"mocha": "^2.0.1",
4240
"react": "0.12.x",
43-
"reactify": "0.15.x",
4441
"rf-release": "0.4.0",
4542
"rx": "2.3.18",
46-
"uglify-js": "2.4.15",
47-
"webpack": "1.4.5",
48-
"webpack-dev-server": "1.6.5"
43+
"uglify-js": "^2.4.16",
44+
"webpack": "^1.4.13",
45+
"webpack-dev-server": "^1.6.6"
4946
},
5047
"peerDependencies": {
5148
"react": "0.12.x"
@@ -65,8 +62,5 @@
6562
"route",
6663
"routes",
6764
"router"
68-
],
69-
"browserify-shim": {
70-
"react": "global:React"
71-
}
72-
}
65+
]
66+
}

scripts/build

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/sh
2-
mkdir -p dist
3-
NODE_ENV=production node_modules/.bin/browserify modules/index.js -t browserify-shim -t envify --detect-globals false -s ReactRouter > dist/react-router.js
4-
node_modules/.bin/uglifyjs dist/react-router.js --compress warnings=false > dist/react-router.min.js
2+
npm run build
3+
npm run build-min
54
echo "gzipped, the global build is:"
65
echo "`gzip -c dist/react-router.min.js | wc -c` bytes"
7-

scripts/test

-2
This file was deleted.

tests.webpack.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var context = require.context('./modules', true, /-test\.js$/);
2+
context.keys().forEach(context);

webpack.config.js

+6-34
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,16 @@
1-
var fs = require('fs');
2-
var path = require('path');
31
var webpack = require('webpack');
42

5-
var EXAMPLES_DIR = path.resolve(__dirname, 'examples');
6-
7-
function isDirectory(dir) {
8-
return fs.lstatSync(dir).isDirectory();
9-
}
10-
113
module.exports = {
124

13-
entry: fs.readdirSync(EXAMPLES_DIR).reduce(function (entries, dir) {
14-
var isDraft = dir.charAt(0) === '_';
15-
16-
if (!isDraft && isDirectory(path.join(EXAMPLES_DIR, dir)))
17-
entries[dir] = path.join(EXAMPLES_DIR, dir, 'app.js');
18-
19-
return entries;
20-
}, {}),
21-
225
output: {
23-
filename: '[name].js',
24-
chunkFilename: '[id].chunk.js',
25-
publicPath: '__build__'
26-
},
27-
28-
module: {
29-
loaders: [
30-
{ test: /\.js$/, loader: 'jsx-loader?harmony' }
31-
]
32-
},
33-
34-
resolve: {
35-
alias: {
36-
'react-router': '../../modules/index'
37-
}
6+
library: 'ReactRouter',
7+
libraryTarget: 'var'
388
},
399

4010
plugins: [
41-
new webpack.optimize.CommonsChunkPlugin('shared.js')
11+
new webpack.DefinePlugin({
12+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
13+
})
4214
]
43-
15+
4416
};

0 commit comments

Comments
 (0)