forked from AngularLovers/angular2-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
145 lines (130 loc) · 4.68 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var webpack = require('webpack'),
ReloadPlugin = require('webpack-reload-plugin'),
path = require('path'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
WebpackNotifierPlugin = require('webpack-notifier'),
ExtractTextPlugin = require('extract-text-webpack-plugin');
/**
* Support for extra commandline arguments
*/
var argv = require('optimist').argv;
/**
* Useful variables
*/
var cwd = process.cwd();
var DEBUG = !argv.release;
var isDevServer = process.argv.join('').indexOf('webpack-dev-server') > -1;
var version = require(path.resolve(cwd,'package.json')).version;
var reloadHost = 'localhost';
var npmRoot = __dirname + '/node_modules';
var appDir = __dirname + '/src';
var entry = ['main.ts'];
if (isDevServer) {
entry.unshift('webpack-dev-server/client?http://'+reloadHost+':8080');
}
function makeConfig(options) {
return {
cache: true,
debug: true,
verbose: true,
displayErrorDetails: true,
context: appDir,
entry: {
vendor: 'vendor.ts',
bundle: entry
},
stats: {
colors: true,
reasons: DEBUG
},
devtool: 'source-map',
recordsPath: path.resolve('.webpack.json'),
devServer: {
inline: true,
colors: true,
header:{
"Access-Control-Allow-Origin":"*"
},
contentBase: path.resolve(cwd, 'dist'),
publicPath: '/'
},
output: {
path: path.resolve(cwd, 'dist'),
filename: '[name].js',
publicPath: '/',
chunkFilename: '[id].bundle.js',
// Hot Module Replacement settings:
hotUpdateMainFilename: 'updates/[hash].update.json',
hotUpdateChunkFilename: 'updates/[hash].[id].update.js'
},
plugins: [
new webpack.IgnorePlugin(/spec\.js$/),
new webpack.optimize.CommonsChunkPlugin('common.js'),
new ExtractTextPlugin('styles.css'),
new webpack.DefinePlugin({
VERSION: JSON.stringify(version),
ENV: JSON.stringify(options.env)
}),
new HtmlWebpackPlugin({
template: path.join(appDir, 'index.html')
}),
new ReloadPlugin( isDevServer ? 'localhost' : ''),
new WebpackNotifierPlugin({
title: 'ng-book',
contentImage: path.join(appDir, 'images', 'favicon.ico')
})
],
resolveLoader: {
root: path.join(__dirname, 'node_modules'),
modulesDirectories: ['node_modules'],
fallback: path.join(__dirname, 'node_modules')
},
resolve: {
root: [path.resolve(cwd)],
modulesDirectories: [
'node_modules', 'src', 'src/ts', '.'
],
extensions: ['', '.ts', '.js', '.json', '.css','.scss'],
alias: {
'src': 'src',
'scripts': npmRoot
}
},
module: {
loaders: [
{ test: /\.(png|jpg|gif|ico)$/, loader: 'file-loader?limit=50000&name=[path][name].[ext]' },
{ test: /\.json$/, loader: 'json' },
{ test: /^.*\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader?sourceMap')},
{ test: /\.scss$/, loaders: [
'raw-loader',
'style-loader',
ExtractTextPlugin.extract('style-loader', 'css-loader?sourceMap'),
'sass-loader' +
'?outputStyle=expanded&' +
'root='+appDir+'&' +
'&includePaths[]'+npmRoot + '&' +
'&includePaths[]'+appDir
]},
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader' },
{ test: /\.html$/, loader: 'raw' },
{ test: /^index\.html$/, loader: 'file-loader?name=[path][name].[ext]' },
{ test: /\.ts$/, loader: 'ts', exclude: [ /test/, /node_modules/]},
{ test: /\.woff(2)?(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader?mimetype=application/font-woff&name=[path][name].[ext]' },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader?mimetype=application/x-font-ttf&name=[path][name].[ext]' },
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?\??$/, loader: 'file-loader?mimetype=application/vnd.ms-fontobject&name=[path][name].[ext]' },
{ test: /\.otf(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader?mimetype=application/font-otf&name=[path][name].[ext]' },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader' }
],
noParse: [
/\.min\.js/,
/vendor\/.*?\.(js|css)$/
]
},
tslint: {
emitErrors: false,
failOnHint: false
}
}
}
var config = makeConfig(argv);
module.exports = config;