Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit d5c68ff

Browse files
試加,毋過失敗 #196
1 parent 6b27791 commit d5c68ff

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"description": "itaigi",
55
"scripts": {
66
"start": "node devServer.js",
7+
"production": "NODE_ENV=production webpack -p --progress --config webpack.config.js && node prerender",
8+
"server": "node prerender",
79
"test": "jscs *.js src/",
810
"reformat": "jscs -x *.js src/",
911
"build": "mkdir -p build;rm -f build/* && NODE_ENV=production webpack --config webpack.config.prod.js && cp index.html favicons/* build/ && cp index.html build/404.html",

prerender/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var express = require("express");
2+
var path = require("path");
3+
var page = require("./bundle.js");
4+
5+
var app = express();
6+
7+
app.use(express.static(path.join(__dirname, "..", "build")));
8+
9+
var stats = require("./stats.generated.json");
10+
11+
app.get("/", function(req, res) {
12+
res.end(page(req, stats.assetsByChunkName.main));
13+
});
14+
15+
var server = app.listen(3000, function() {
16+
console.log('Listening on port %d', server.address().port);
17+
});

webpack.config.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var path = require('path');
2+
var webpack = require('webpack');
3+
4+
module.exports = {
5+
devtool: 'source-map',
6+
entry: [
7+
'./src',
8+
],
9+
10+
target: "node",
11+
output: {
12+
path: path.join(__dirname, 'prerender'),
13+
filename: 'bundle.js',
14+
publicPath: '/',
15+
},
16+
plugins: [
17+
new webpack.optimize.OccurenceOrderPlugin(),
18+
new webpack.DefinePlugin({
19+
'process.env': {
20+
NODE_ENV: JSON.stringify('production'),
21+
},
22+
"global.GENTLY": false
23+
}),
24+
new webpack.optimize.UglifyJsPlugin({
25+
compressor: {
26+
warnings: false,
27+
},
28+
}),
29+
],
30+
resolve: {
31+
extensions: ['', '.js', '.jsx'],
32+
},
33+
module: {
34+
loaders: [
35+
{
36+
test: /\.jsx?/,
37+
loaders: ['babel', 'strict'],
38+
include: path.join(__dirname, 'src'),
39+
},
40+
{
41+
test: /\.css$/,
42+
loader: 'style-loader!css-loader!postcss-loader',
43+
},
44+
{
45+
test: /\.(png|jpg|gif|svg)$/,
46+
loader: 'url-loader?limit=1',
47+
},
48+
{
49+
test: /\.json$/,
50+
loader: 'json-loader',
51+
},
52+
],
53+
},
54+
};

0 commit comments

Comments
 (0)