-
Notifications
You must be signed in to change notification settings - Fork 131
/
webpack.config.js
87 lines (80 loc) · 2.26 KB
/
webpack.config.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
var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var autoprefixer = require('autoprefixer');
var commonConfig = {
resolve: {
extensions: ['.ts', '.js', '.json', '.css', '.scss', '.html']
},
module: {
loaders: [
// TypeScript
{ test: /\.ts$/, loaders: ['angular2-template-loader', 'awesome-typescript-loader'] },
{ test: /\.html$/, loaders: ['raw-loader'] },
{ test: /\.css$/, loaders: ['css-loader', 'raw-loader'] },
{ test: /\.json$/, loader: 'raw-loader' },
{
test: /\.scss$/,
exclude: root('src', 'app'),
loaders: ["raw-loader", "csso-loader", "sass-loader"]
},
// all css required in src/app files will be merged in js files
{ test: /\.scss$/, exclude: root('src', 'assets', 'style'), loader: 'raw!sass' }
]
// preLoaders: [
// // needed to lower the filesize of angular due to inline source-maps
// { test: /\.js$/, loader: 'source-map-loader' }
// ]
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(true),
new ExtractTextPlugin({ filename: "css/[name].css", disable: false, allChunks: true }),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]
};
var serverConfig = {
target: 'node',
entry: './src/server', // use the entry file of the node server if everything is ts rather than es5
output: {
path: root('dist/server'),
libraryTarget: 'commonjs2'
},
externals: checkNodeImport,
node: {
global: true,
__dirname: true,
__filename: true,
process: true,
Buffer: true
},
devtool: 'eval'
};
// Default config
var defaultConfig = {
context: __dirname,
output: {
publicPath: path.resolve(__dirname),
filename: 'index.js'
}
};
var webpackMerge = require('webpack-merge');
module.exports = [
// Server
webpackMerge({}, defaultConfig, commonConfig, serverConfig)
]
// Helpers
function checkNodeImport(context, request, cb) {
if (!path.isAbsolute(request) && request.charAt(0) !== '.') {
cb(null, 'commonjs2 ' + request);
return;
}
cb();
}
function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [__dirname].concat(args));
}