-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.server.js
87 lines (78 loc) · 2.12 KB
/
webpack.server.js
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
/**
* Webpack configuration for the server.
* @copyright (c) 2016-present [email protected]
*/
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const isProduction = process.env.NODE_ENV === 'production';
const productionConfig = {
devtool: 'source-map',
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
};
/**
* Create list of external webpack modules.
* @method createExternals
* @returns {object} List of external modules.
*/
const createExternals = () => {
const nodeModules = {};
fs.readdirSync('node_modules')
.filter((x) => ['.bin'].indexOf(x) === -1)
.forEach((mod) => {
nodeModules[mod] = 'commonjs ' + mod;
});
return nodeModules;
};
/**
* Create back-end webpack configuration.
* @method createConfig
* @returns {object} Webpack configuration.
*/
function createConfig() {
const config = {
entry: {
app: [path.join(__dirname, 'app.js')],
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
},
target: 'node',
cache: true,
devtool: 'eval',
resolve: {
modulesDirectories: [
'src', 'node_modules', 'static'
],
extensions: ['', '.js', '.jsx', '.json'],
root: path.join(__dirname, 'src'),
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: ['babel']
}, {
test: /\.json$/,
loaders: ['json']
}, {
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader'
}],
noParse: /\.min\.js/
},
externals: createExternals(),
node: {
__dirname: true,
fs: 'empty'
}
};
if (isProduction) return webpackMerge(config, productionConfig);
return config;
}
module.exports = createConfig;