1
|
var webpack = require('webpack');
|
2
|
var path = require('path');
|
3
|
var clone = require('js.clone');
|
4
|
var webpackMerge = require('webpack-merge');
|
5
|
|
6
|
export var commonPlugins = [
|
7
|
new webpack.ContextReplacementPlugin(
|
8
|
// The (\\|\/) piece accounts for path separators in *nix and Windows
|
9
|
/angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
|
10
|
root('./src'),
|
11
|
{
|
12
|
// your Angular Async Route paths relative to this root directory
|
13
|
}
|
14
|
),
|
15
|
|
16
|
// Loader options
|
17
|
new webpack.LoaderOptionsPlugin({
|
18
|
|
19
|
}),
|
20
|
|
21
|
];
|
22
|
export var commonConfig = {
|
23
|
// https://webpack.github.io/docs/configuration.html#devtool
|
24
|
devtool: 'source-map',
|
25
|
resolve: {
|
26
|
extensions: ['.ts', '.js', '.json'],
|
27
|
modules: [ root('node_modules') ]
|
28
|
},
|
29
|
context: __dirname,
|
30
|
output: {
|
31
|
publicPath: '',
|
32
|
filename: '[name].bundle.js'
|
33
|
},
|
34
|
module: {
|
35
|
rules: [
|
36
|
// TypeScript
|
37
|
{ test: /\.ts$/, use: ['awesome-typescript-loader', 'angular2-template-loader'] },
|
38
|
{ test: /\.html$/, use: 'raw-loader' },
|
39
|
{ test: /\.css$/, use: 'raw-loader' },
|
40
|
{ test: /\.json$/, use: 'json-loader' }
|
41
|
],
|
42
|
},
|
43
|
plugins: [
|
44
|
// Use commonPlugins.
|
45
|
]
|
46
|
|
47
|
};
|
48
|
|
49
|
// Client.
|
50
|
export var clientPlugins = [
|
51
|
|
52
|
];
|
53
|
export var clientConfig = {
|
54
|
target: 'web',
|
55
|
entry: './src/client',
|
56
|
output: {
|
57
|
path: root('dist/client')
|
58
|
},
|
59
|
node: {
|
60
|
global: true,
|
61
|
crypto: 'empty',
|
62
|
__dirname: true,
|
63
|
__filename: true,
|
64
|
process: true,
|
65
|
Buffer: false
|
66
|
}
|
67
|
};
|
68
|
|
69
|
|
70
|
// Server.
|
71
|
export var serverPlugins = [
|
72
|
|
73
|
];
|
74
|
export var serverConfig = {
|
75
|
target: 'node',
|
76
|
entry: './src/server', // use the entry file of the node server if everything is ts rather than es5
|
77
|
output: {
|
78
|
filename: 'index.js',
|
79
|
path: root('dist/server'),
|
80
|
libraryTarget: 'commonjs2'
|
81
|
},
|
82
|
module: {
|
83
|
rules: [
|
84
|
{ test: /@angular(\\|\/)material/, use: "imports-loader?window=>global" }
|
85
|
],
|
86
|
},
|
87
|
externals: includeClientPackages(
|
88
|
/@angularclass|@angular|angular2-|ng2-|ng-|@ng-|angular-|@ngrx|ngrx-|@angular2|ionic|@ionic|-angular2|-ng2|-ng/
|
89
|
),
|
90
|
node: {
|
91
|
global: true,
|
92
|
crypto: true,
|
93
|
__dirname: true,
|
94
|
__filename: true,
|
95
|
process: true,
|
96
|
Buffer: true
|
97
|
}
|
98
|
};
|
99
|
|
100
|
export default [
|
101
|
// Client
|
102
|
webpackMerge(clone(commonConfig), clientConfig, { plugins: clientPlugins.concat(commonPlugins) }),
|
103
|
|
104
|
// Server
|
105
|
webpackMerge(clone(commonConfig), serverConfig, { plugins: serverPlugins.concat(commonPlugins) })
|
106
|
];
|
107
|
|
108
|
|
109
|
|
110
|
|
111
|
// Helpers
|
112
|
export function includeClientPackages(packages, localModule?: string[]) {
|
113
|
return function(context, request, cb) {
|
114
|
if (localModule instanceof RegExp && localModule.test(request)) {
|
115
|
return cb();
|
116
|
}
|
117
|
if (packages instanceof RegExp && packages.test(request)) {
|
118
|
return cb();
|
119
|
}
|
120
|
if (Array.isArray(packages) && packages.indexOf(request) !== -1) {
|
121
|
return cb();
|
122
|
}
|
123
|
if (!path.isAbsolute(request) && request.charAt(0) !== '.') {
|
124
|
return cb(null, 'commonjs ' + request);
|
125
|
}
|
126
|
return cb();
|
127
|
};
|
128
|
}
|
129
|
|
130
|
export function root(args) {
|
131
|
args = Array.prototype.slice.call(arguments, 0);
|
132
|
return path.join.apply(path, [__dirname].concat(args));
|
133
|
}
|