-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.server.config.js
More file actions
109 lines (93 loc) · 2.92 KB
/
Copy pathwebpack.server.config.js
File metadata and controls
109 lines (93 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// @flow
// config file for the production
// express server
var webpack = require("webpack");
var fs = require("fs");
var path = require("path"),
src = path.join(__dirname, "src"),
dest = path.join(__dirname, "public"),
modules = path.join(__dirname, "node_modules");
var NODE_ENV = process.env.NODE_ENV;
var isDev = NODE_ENV == "development";
// define variable __DEV__ to allow for development
// mode specific code execution
var devPlugin = new webpack.DefinePlugin({
__DEV__: JSON.stringify(isDev)
});
// css modules naming scheme
var cssModulesNames = (
isDev ? "[path][name]__[local]__" : "") + "[hash:base64:5]";
// css extraction (necessary for isomorphic behaviour)
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var config = {
entry: path.join(__dirname, "server.js"),
output: {
path: __dirname,
filename: "server.bundle.js"
},
// the built bundles are targeted towards
// node.js, as we will be doing server side
// rendering of React components
target: "node",
externals: fs.readdirSync(modules)
.concat(["react-dom/server", "react/addons"]).reduce(
(ext, mod) => {
ext[mod] = "commonjs " + mod;
return ext;
}, {}),
node: {
__filename: true,
__dirname: true
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader:"babel",
exclude: /node_modules/
},
{
test: /\.module\.css$/,
include: src,
loader: ExtractTextPlugin.extract(
"style",
"css-loader?modules&localIdentName=" + cssModulesNames,
"postcss"
)
},
{
test: /\.css$/,
include: modules,
loader: ExtractTextPlugin.extract("style", "css")
},
{
test: /\.(png|ico|tiff|pdf)$/,
include: src,
loader: "url?limit=10000"
}
]
},
// add .jsx extension for JSX files
resolve: {
// some aliases for easy requires in server.js
alias: {
components: path.join(src, "components"),
containers: path.join(src, "containers"),
styles: path.join(src, "styles"),
utils: path.join(src, "utils"),
routes: path.join(src, "routes"),
modules: modules
},
extensions: ["", ".js", ".jsx", ".webpack.js"]
},
plugins: (isDev ? [] : []).concat([devPlugin, new ExtractTextPlugin("public/styles/[name].css")]),
// postcss config
// it is possible to modify these postcss Processors
// through the object argument.
postcss: [
require("autoprefixer")({}),
require("cssnano")({}),
require("precss")({})
]
};
module.exports = config;