-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
120 lines (112 loc) · 2.64 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
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var merge = require('./lib/merge');
var webpack = require('webpack');
var TARGET = process.env.TARGET;
var ROOT_PATH = path.resolve(__dirname);
var common = {
entry: [path.join(ROOT_PATH, 'app/main.jsx')],
resolve: {
extensions: ['', '.js', '.jsx'],
},
output: {
path: path.resolve(ROOT_PATH, 'build'),
filename: 'bundle.js',
},
module: {
preLoaders: [
{
test: /\.js$/,
// define an include so we check just the files we need
include: path.join(ROOT_PATH, 'app'),
loader: 'jshint'
}
],
loaders: [
{
test: /\.css$/,
loaders: ['style', 'css']
},
{
// test for both js and jsx
test: /\.jsx?$/,
// use babel loader
loader: 'babel',
// operate only on our app directory
include: path.join(ROOT_PATH, 'app'),
}
]
},
};
var mergeConfig = merge.bind(null, common);
if(TARGET === 'build') {
module.exports = mergeConfig({
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
include: path.join(ROOT_PATH, 'app'),
},
],
},
plugins: [
new HtmlWebpackPlugin({
title: 'Kanban app'
}),
// makes the build smaller
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
}),
new webpack.DefinePlugin({
'process.env': {
// This has effect on the react lib size
'NODE_ENV': JSON.stringify('production'),
}
})
],
});
}
if(TARGET === 'dev') {
var IP = '0.0.0.0';
var PORT = 8080;
module.exports = mergeConfig({
ip: IP,
port: PORT,
entry: [
'webpack-dev-server/client?http://' + IP + ':' + PORT,
'webpack/hot/dev-server',
],
module: {
// preLoaders: [
// {
// test: /\.jsx?$/,
// // we are using `eslint-loader` explicitly since
// // we have ESLint module installed. This way we
// // can be certain that it uses the right loader
// loader: 'eslint-loader',
// include: path.join(ROOT_PATH, 'app'),
// }
// ],
loaders: [
{
test: /\.jsx?$/,
loaders: ['react-hot', 'babel'],
include: path.join(ROOT_PATH, 'app'),
},
],
},
output: {
path: __dirname,
filename: 'bundle.js',
publicPath: '/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new HtmlWebpackPlugin(),
]
});
}