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

Static site generator #82

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules
/build
.vagrant
.idea
7 changes: 7 additions & 0 deletions lib/static-build-assets/build-static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require('shelljs/global');

exec('git stash');
cp('-f', 'lib/static-build-assets/staticSite.html', 'build/public/index.html');
exec('git branch gh-pages');
exec('git checkout gh-pages');
cp('-rf', './build/public/*', '.');
12 changes: 12 additions & 0 deletions lib/static-build-assets/staticSite.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="main.css"/>
</head>
<body>
<div id="content"></div>
</body>
<script src="main.js"></script>
</html>

12 changes: 12 additions & 0 deletions lib/staticSite.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="main.css"/>
</head>
<body>
<div id="content"></div>
</body>
<script src="main.js"></script>
</html>

23 changes: 13 additions & 10 deletions make-webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ module.exports = function(options) {
if(options.commonsChunk) {
plugins.push(new webpack.optimize.CommonsChunkPlugin("commons", "commons.js" + (options.longTermCaching && !options.prerender ? "?[chunkhash]" : "")));
}
var asyncLoader = {
test: require("./app/route-handlers/async").map(function(name) {
return path.join(__dirname, "app", "route-handlers", name);
}),
loader: options.prerender ? "react-proxy-loader/unavailable" : "react-proxy-loader"
};



if(!options.staticSite){
var asyncLoader = {
test: require("./app/route-handlers/async").map(function(name) {
return path.join(__dirname, "app", "route-handlers", name);
}),
loader: options.prerender ? "react-proxy-loader/unavailable" : "react-proxy-loader"
};
}
Object.keys(stylesheetLoaders).forEach(function(ext) {
var stylesheetLoader = stylesheetLoaders[ext];
if(Array.isArray(stylesheetLoader)) stylesheetLoader = stylesheetLoader.join("!");
Expand Down Expand Up @@ -135,12 +135,15 @@ module.exports = function(options) {
);
}

var loaderStart = typeof asyncLoader !== 'undefined' ? [asyncLoader] : [];
return {
entry: entry,
output: output,
target: options.prerender ? "node" : "web",
module: {
loaders: [asyncLoader].concat(loadersByExtension(loaders)).concat(loadersByExtension(stylesheetLoaders)).concat(additionalLoaders)
loaders: loaderStart.concat(loadersByExtension(loaders))
.concat(loadersByExtension(stylesheetLoaders))
.concat(additionalLoaders)
},
devtool: options.devtool,
debug: options.debug,
Expand All @@ -163,4 +166,4 @@ module.exports = function(options) {
}
}
};
};
};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"dev-server": "webpack-dev-server --config webpack-dev-server.config.js --progress --colors --port 2992 --inline",
"hot-dev-server": "webpack-dev-server --config webpack-hot-dev-server.config.js --hot --progress --colors --port 2992 --inline",
"build": "webpack --config webpack-production.config.js --progress --profile --colors",
"build-static": "webpack --config webpack-static-site.config.js --progress --profile --colors && node lib/static-build-assets/build-static.js",
"deploy-static": "npm run build-static && git add . && git commit -m \"Automated commit on `date +%Y-%m-%d:%H:%M:%S`\"",
"start-dev": "node lib/server-development",
"start": "node lib/server-production"
},
Expand Down Expand Up @@ -50,6 +52,7 @@
"devDependencies": {
"babel-eslint": "^3.0.1",
"eslint": "^0.22.0",
"eslint-plugin-react": "^2.2.0"
"eslint-plugin-react": "^2.2.0",
"shelljs": "^0.5.1"
}
}
13 changes: 13 additions & 0 deletions webpack-static-site.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = [
require("./make-webpack-config")({
longTermCaching: true,
separateStylesheet: true,
minimize: true,
staticSite:true
}),
require("./make-webpack-config")({
prerender: true,
minimize: true,
staticSite:true
})
];