-
Notifications
You must be signed in to change notification settings - Fork 39
/
webpack.config.js
141 lines (136 loc) · 3.85 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
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var autoprefixer = require('autoprefixer');
var args = require('yargs').argv;
// parameters
var isProd = args.prod;
var isMock = args.mock;
var base = './';
// use mock api or not
var entryJs = isMock ?
base + 'source/test/e2e/mocks/index.js' :
base + 'source/app/index.js';
var appName = isMock ? 'appTest' : 'app';
var plugins = [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
// materialize-css rely on this to support velocity
"window.jQuery": "jquery"
}),
new webpack.DefinePlugin({
__PROD__: isProd,
__MOCK__: isMock
}),
new webpack.optimize.CommonsChunkPlugin('vendor', isProd ? 'vendor.[hash].js' : 'vendor.js'),
new ExtractTextPlugin(isProd ? '[name].[hash].css' : '[name].css'),
new HtmlWebpackPlugin({
template: 'jade!./source/app/index.jade',
chunks: ['app', 'vendor'],
favicon: 'favicon.ico',
appName: appName
}),
new CopyWebpackPlugin([
{ from: 'node_modules/babel-core/browser-polyfill.min.js', to: 'polyfill.js'}
])
];
if (isProd) {
plugins.push(
new webpack.NoErrorsPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
mangle: false
}),
new webpack.optimize.OccurenceOrderPlugin()
);
}
module.exports = {
entry: {
app: [
entryJs
],
vendor: [
// 3rd dependencies
'materialize-css/bin/materialize.css',
'materialize-css/bin/materialize.js',
'animate.css/animate.css',
// angular
'angular',
'angular-ui-router',
'angular-animate',
'angular-messages',
'angular-mocks',
'angular-loading-bar',
'oclazyload'
]
},
output: {
path: base + 'build',
filename: isProd ? '[name].[hash].js' : '[name].js',
chunkFilename: isProd ? '[name].[hash].chunk.js' : '[name].chunk.js'
},
module: {
preLoaders: [
{
test: /\.js$/,
loader: "eslint",
exclude: /node_modules/
}
],
loaders: [
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
},
{
test: /\.html$/,
loader: 'html'
},
{
test: /\.jade$/,
loader: 'jade',
exclude: /index\.jade/
},
{
test: /\.styl$/,
loader: ExtractTextPlugin.extract('style', 'css?sourceMap!postcss!stylus')
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css?sourceMap')
},
{
test: /\.(woff|woff2|ttf|eot|svg)(\?]?.*)?$/,
loader : 'file?name=assets/fonts/[name].[ext]?[hash]'
},
{
test: /\.(png|jpg)$/,
loader: 'url?limit=8192&name=assets/images/[name].[hash].[ext]'
}
]
},
plugins: plugins,
debug: !isProd,
devtool: isProd ? 'source-map' : 'eval-source-map',
devServer: {
contentBase: base + 'build',
historyApiFallback: true,
stats: {
modules: false,
cached: false,
colors: true,
chunk: false
},
host: '0.0.0.0',
port: 8080
},
postcss: function () {
return [autoprefixer];
}
};