1
|
var webpack = require('webpack');
|
2
|
var path = require('path');
|
3
|
|
4
|
var commonConfig = {
|
5
|
resolve: {
|
6
|
extensions: ['', '.ts', '.js', '.json']
|
7
|
},
|
8
|
module: {
|
9
|
loaders: [
|
10
|
// TypeScript
|
11
|
{ test: /\.ts$/, loaders: ['ts-loader', 'angular2-template-loader'] },
|
12
|
{ test: /\.html$/, loader: 'raw-loader' },
|
13
|
{ test: /\.css$/, loader: 'raw-loader' },
|
14
|
{ test: /\.json$/, loader: 'raw-loader' }
|
15
|
],
|
16
|
},
|
17
|
plugins: [
|
18
|
]
|
19
|
|
20
|
};
|
21
|
|
22
|
|
23
|
var clientConfig = {
|
24
|
target: 'web',
|
25
|
entry: './src/client',
|
26
|
output: {
|
27
|
path: root('dist/client')
|
28
|
},
|
29
|
node: {
|
30
|
global: true,
|
31
|
__dirname: true,
|
32
|
__filename: true,
|
33
|
process: true,
|
34
|
Buffer: false
|
35
|
}
|
36
|
};
|
37
|
|
38
|
|
39
|
var serverConfig = {
|
40
|
target: 'node',
|
41
|
entry: './src/server', // use the entry file of the node server if everything is ts rather than es5
|
42
|
output: {
|
43
|
path: root('dist/server'),
|
44
|
libraryTarget: 'commonjs2'
|
45
|
},
|
46
|
externals: checkNodeImport,
|
47
|
node: {
|
48
|
global: true,
|
49
|
__dirname: true,
|
50
|
__filename: true,
|
51
|
process: true,
|
52
|
Buffer: true
|
53
|
}
|
54
|
};
|
55
|
|
56
|
|
57
|
|
58
|
// Default config
|
59
|
var defaultConfig = {
|
60
|
context: __dirname,
|
61
|
resolve: {
|
62
|
root: root('/src')
|
63
|
},
|
64
|
output: {
|
65
|
publicPath: path.resolve(__dirname),
|
66
|
filename: 'index.js'
|
67
|
}
|
68
|
}
|
69
|
|
70
|
|
71
|
|
72
|
var webpackMerge = require('webpack-merge');
|
73
|
module.exports = [
|
74
|
// Client
|
75
|
webpackMerge({}, defaultConfig, commonConfig, clientConfig),
|
76
|
|
77
|
// Server
|
78
|
webpackMerge({}, defaultConfig, commonConfig, serverConfig)
|
79
|
]
|
80
|
|
81
|
// Helpers
|
82
|
function checkNodeImport(context, request, cb) {
|
83
|
if (!path.isAbsolute(request) && request.charAt(0) !== '.') {
|
84
|
cb(null, 'commonjs ' + request); return;
|
85
|
}
|
86
|
cb();
|
87
|
}
|
88
|
|
89
|
function root(args) {
|
90
|
args = Array.prototype.slice.call(arguments, 0);
|
91
|
return path.join.apply(path, [__dirname].concat(args));
|
92
|
}
|