forked from PulseTile/PulseTile-AngularJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
230 lines (196 loc) · 5.73 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
229
230
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 ENV_PRODUCTION_EXTENSION = NODE_ENV === 'extension';
const HOST = process.env.HOST || 'localhost';
const PORT = process.env.PORT || 9000;
const API_URL = 'http://46.101.95.245';
// const API_URL = 'http://178.62.6.217';
// 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!"}
]
},
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',
'jQuery': 'jquery',
'window.jQuery': 'jquery',
"moment": "moment",
Raphael: 'raphael',
io: 'socket.io-client',
swiper: 'swiper',
})
],
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 || ENV_PRODUCTION_EXTENSION) {
config.entry = {
index: [
'bootstrap-loader',
'./src/app/index'
],
vendor: './src/app/vendor'
};
if (ENV_PRODUCTION_EXTENSION) {
config.entry.index[1] = './src/app/plugins-extension';
}
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'
}),
new HtmlWebpackPlugin({
filename: 'ui-kit.html',
hash: true,
inject: 'body',
favicon: './src/favicon.png',
template: './src/ui-kit.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 || ENV_PRODUCTION_EXTENSION) {
config.devtool = 'source-map';
config.module.loaders.push(
{test: /\.scss$/, loader: 'style!css!postcss!sass'}
);
config.plugins.push(
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.DedupePlugin()
);
}
//=====================================
// 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'}
);
config.module.preLoaders = [
{ test: /\.js$/, loader: 'isparta', include: path.join(__dirname, 'src/app') }
];
}
module.exports = config;