-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·110 lines (102 loc) · 2.44 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
var webpack = require('webpack');
// var Dashboard = require('webpack-dashboard');
// var DashboardPlugin = require('webpack-dashboard/plugin');
var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
var WebpackDevServer = require('webpack-dev-server');
var path = require('path');
var appName = 'app';
var host = '0.0.0.0';
var port = '9000';
var env = process.env.NODE_ENV || 'dev';
var plugins = [];
var outputFile = appName + '.js';
// Conditionally add plugins for Production builds.
if (env === 'production' || env === 'staging') {
// Always expose NODE_ENV to webpack, you can now use `process.env.NODE_ENV`
// inside your code for any environment checks; UglifyJS will automatically
// drop any unreachable code.
plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
}));
plugins.push(new UglifyJsPlugin({ minimize: true }));
}
// Conditionally add plugins for Development
else {
plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
}));
}
var config = {
devtool: 'source-map',
quiet: true,
entry: './src/index.js',
output: {
path: path.join(__dirname, '/base'),
publicPath: '/',
filename: outputFile
},
module: {
loaders: [
{
test: /(\.jsx|\.js)$/,
loader: ['babel'],
exclude: /(node_modules|bower_components)/,
query: {
presets: ['react', 'es2015']
}
},
{
test: /(\.jsx|\.js)$/,
loader: "eslint-loader",
exclude: /node_modules/
},
{
test: /\.scss$/,
include: /src/,
loaders: [
'style',
'css',
'autoprefixer?browsers=last 3 versions',
'sass?outputStyle=expanded'
]
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'url?limit=8192',
'img'
]
},
{
test: /\.json$/,
loader: 'json'
}
]
},
resolve: {
root: path.resolve('./src'),
extensions: ['', '.js', '.jsx']
},
plugins: plugins
};
if (env === 'dev') {
var compiler = webpack(config);
new WebpackDevServer(compiler, {
contentBase: './base/',
hot: true,
quiet: true,
lazy: false,
historyApiFallback: {
index: '/'
}
}).listen(port, host, function (err, result) {
if (err) {
console.log(err);
}
});
}
module.exports = config;