-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
228 lines (196 loc) · 6.13 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BowerWebpackPlugin = require('bower-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
//=========================================================
// ENVIRONMENT VARS
//---------------------------------------------------------
const NODE_ENV = process.env.NODE_ENV;
const ENV_DEVELOPMENT = NODE_ENV === 'development';
const ENV_PRODUCTION = NODE_ENV === 'production';
const ENV_TEST = NODE_ENV === 'test';
const ENV_COPY = NODE_ENV === 'copy';
const HOST = process.env.HOST || 'localhost';
const PORT = process.env.PORT || 9000;
// const API_URL = process.env.API_URL || 'http://localhost:19191';
const API_URL = 'http://138.68.134.7';
// const API_URL = 'http://139.59.187.100';
//=========================================================
// CONFIG
//---------------------------------------------------------
const config = {
resolve: {
extensions: ['', '.js'],
modulesDirectories: ["node_modules", "bower_components"],
root: path.resolve('./src'),
alias: {
'morrisjs': '../../bower_components/morrisjs/morris.js',
'spin': 'spin.js'
}
},
module: {
loaders: [
{test: /\.js$/, exclude: /node_modules/, loader: 'ng-annotate!babel'},
{test: /\.html$/, loader: 'html'},
{test: /\.(woff|woff2)/, loader: 'url?prefix=fonts/&limit=10000&mimetype=application/font-woff&name=assets/fonts/[name].[ext]'},
{test: /\.(ttf|eot|svg)/, loader: 'file?name=assets/fonts/[name].[ext]'},
{test: /\.(jpg|png|jpeg|gif)$/, loader: 'url-loader?limit=25000/&name=assets/images/[name].[ext]' },
{test: /\.css$/, loader: "style-loader!css-loader!"}
/*{test: /\.woff(\?.*)?$/,loader: 'url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/font-woff'},
{test: /\.woff2(\?.*)?$/, loader: 'url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/font-woff2' },
{test: /\.otf(\?.*)?$/, loader: 'file?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=font/opentype' },
{test: /\.ttf(\?.*)?$/, loader: 'url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/octet-stream' },
{test: /\.eot(\?.*)?$/, loader: 'file?prefix=fonts/&name=[path][name].[ext]' },
{test: /\.svg(\?.*)?$/, loader: 'url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=image/svg+xml' },
{test: /\.(png|jpg)$/, loader: 'url?limit=8192'}*/
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
}),
new BowerWebpackPlugin({
excludes: ['node_modules'],
modulesDirectories: ['bower_components']
}),
new webpack.ResolverPlugin(
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin(".bower.json", ["main"])
),
new webpack.ProvidePlugin({
angularSpinner: 'angular-spinner',
_: 'underscore',
$: "jquery",
"window.jQuery": "jquery",
jQuery: "jquery",
"moment": "moment",
Raphael: 'raphael'
})
],
postcss: [
autoprefixer({ browsers: ['last 3 versions'] })
],
sassLoader: {
outputStyle: 'compressed',
precision: 10,
sourceComments: false,
includePaths: [
'./src/app/scss'
]
}
};
//=====================================
// DEVELOPMENT or PRODUCTION
//-------------------------------------
if (ENV_DEVELOPMENT || ENV_PRODUCTION) {
config.entry = {
index: [
'bootstrap-loader',
'./src/app/index'
],
vendor: './src/app/vendor'
};
config.output = {
filename: '[name].js',
path: path.resolve('./dist'),
publicPath: ''
};
config.plugins.push(
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity
}),
new HtmlWebpackPlugin({
filename: 'index.html',
hash: true,
inject: 'body',
favicon: './src/favicon.png',
template: './src/index.html'
})
);
}
//=====================================
// DEVELOPMENT
//-------------------------------------
if (ENV_DEVELOPMENT) {
config.devtool = 'cheap-module-source-map';
config.entry.index.unshift(`webpack-dev-server/client?http://${HOST}:${PORT}`);
config.module.loaders.push(
{test: /\.scss$/, loader: 'style!css!postcss!sass'}
);
config.devServer = {
contentBase: './src',
host: HOST,
port: PORT,
publicPath: config.output.publicPath,
stats: {
cached: true,
cachedAssets: true,
chunks: true,
chunkModules: false,
colors: true,
hash: false,
reasons: true,
timings: true,
version: false
},
proxy: {
'/api/*': {
target: API_URL
}
},
historyApiFallback: true
};
}
//=====================================
// PRODUCTION
//-------------------------------------
if (ENV_PRODUCTION) {
config.devtool = 'source-map';
config.module.loaders.push(
{test: /\.scss$/, loader: 'style!css!postcss!sass'}
);
config.plugins.push(
// new ExtractTextPlugin('styles.css'),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
mangle: false,
beautify: true,
compress: {
dead_code: true, // eslint-disable-line camelcase
screw_ie8: true, // eslint-disable-line camelcase
unused: true,
warnings: false
}
})
);
}
//=====================================
// COPY FILES
//-------------------------------------
if (ENV_COPY) {
config.output = {
filename: '[name].[ext]',
publicPath: ''
};
config.module.loaders.push(
{test: /\.scss$/, loader: 'style!css!postcss!sass'}
);
config.plugins.push(
new CopyWebpackPlugin([
{ from: './bower_components/moment', to: './build' }
])
);
}
//=====================================
// TEST
//-------------------------------------
if (ENV_TEST) {
config.devtool = 'inline-source-map';
config.module.loaders.push(
{test: /\.scss$/, loader: 'style!css!postcss!sass'}
);
}
module.exports = config;