Skip to content

Commit 45dee7d

Browse files
committed
cleanup; added build script for gh-pages
1 parent 40a711a commit 45dee7d

File tree

6 files changed

+323
-241
lines changed

6 files changed

+323
-241
lines changed

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
indent_style = space
8+
insert_final_newline = true
9+
10+
[*.{html,js,css,md}]
11+
indent_size = 2

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
npm-debug.log.*
33
npm-debug.log
44
lib/
5+
gh-pages/

build.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Compiles and builds for the gh-pages branch into the gh-pages folder.
3+
*/
4+
5+
import fs from 'fs';
6+
import path from 'path';
7+
import webpack from 'webpack';
8+
import config from './examples/webpack.config';
9+
10+
const ghpConfig = Object.assign({}, config);
11+
ghpConfig.output.path = path.resolve(__dirname, 'gh-pages');
12+
ghpConfig.devtool = null;
13+
14+
config.entry.shift(); // remove eventsource-polyfill
15+
config.entry.shift(); // remove hmr entry
16+
config.plugins.shift(); // remove hmr plugin
17+
18+
// create a webpack compiler
19+
const compiler = webpack(ghpConfig);
20+
21+
// build!
22+
compiler.run((err, stats) => {
23+
if (err) {
24+
console.error(err);
25+
}
26+
});
27+
28+
// copies the index.html to the dist folder
29+
const ghpPath = path.resolve(__dirname, 'gh-pages');
30+
const indexFile = path.resolve(__dirname, 'examples', 'index.html');
31+
const outIndexFile = path.resolve(ghpPath, 'index.html');
32+
try {
33+
fs.mkdir(ghpPath, (err) => {
34+
if (err) {
35+
console.error(err);
36+
}
37+
fs.createReadStream(indexFile).pipe(fs.createWriteStream(outIndexFile));
38+
});
39+
} catch (copyErr) {
40+
if (copyErr.code === 'EEXIST') {
41+
fs.createReadStream(indexFile).pipe(fs.createWriteStream(outIndexFile));
42+
} else {
43+
console.error(copyErr);
44+
}
45+
}

examples/bundle.js

+255-231
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/webpack.config.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@ module.exports = {
88
entry : [
99
'eventsource-polyfill', // necessary for hot reloading with IE
1010
'webpack-hot-middleware/client',
11-
path.join(__dirname, 'index.js')
11+
path.join(__dirname, 'index.js'),
1212
],
1313
output: {
1414
publicPath: '/',
1515
path: __dirname,
16-
filename: 'bundle.js'
16+
filename: 'bundle.js',
1717
},
1818
module: {
1919
loaders: [
2020
{
2121
test: /\.css$/,
22-
loaders: ['style', 'css?modules']
22+
loaders: ['style', 'css?modules'],
2323
},
2424
{
2525
test: /\.js$/,
2626
exclude: /node_modules/,
27-
loaders: ['babel']
28-
}
29-
]
27+
loaders: ['babel'],
28+
},
29+
],
3030
},
3131
plugins: [
3232
new webpack.HotModuleReplacementPlugin(),
33-
new webpack.NoErrorsPlugin()
33+
new webpack.NoErrorsPlugin(),
3434
],
3535
resolve: {
3636
alias: {
37-
"react-offcanvas": path.resolve('src')
38-
}
37+
"react-offcanvas": path.resolve(__dirname, '..', 'src'),
38+
},
3939
},
4040
};

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"clean": "rimraf lib",
1212
"lint": "eslint ./src",
1313
"compile": "babel ./src -d ./lib",
14-
"build": "npm run clean && npm run compile",
14+
"build-ghp": "cross-env NODE_ENV=production babel-node build.js",
15+
"build": "cross-env NODE_ENV=production npm run clean && npm run compile",
1516
"webpack": "webpack --config ./examples/webpack.config.js",
1617
"devServer": "node ./examples/devServer.js",
1718
"dev": "npm run webpack && npm run devServer",

0 commit comments

Comments
 (0)