forked from DimiMikadze/express-react-redux-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
104 lines (95 loc) · 2.88 KB
/
webpack.config.js
File metadata and controls
104 lines (95 loc) · 2.88 KB
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
var Path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var Webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var isProduction = process.env.NODE_ENV === 'production';
var cssOutputPath = isProduction ? '/styles/app.[hash].css' : '/styles/app.css';
var jsOutputPath = isProduction ? '/scripts/app.[hash].js' : '/scripts/app.js';
var ExtractSASS = new ExtractTextPlugin(cssOutputPath);
var port = isProduction ? process.env.PORT || 8080 : process.env.PORT || 3000;
// ------------------------------------------
// Base
// ------------------------------------------
var webpackConfig = {
resolve: {
extensions: ['', '.js', '.jsx'],
},
plugins: [
new Webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(isProduction ? 'production' : 'development'),
},
}),
new HtmlWebpackPlugin({
template: Path.join(__dirname, './src/index.html'),
}),
],
module: {
loaders: [{
test: /.jsx?$/,
include: Path.join(__dirname, './src/app'),
loader: 'babel',
}],
},
};
// ------------------------------------------
// Entry points
// ------------------------------------------
webpackConfig.entry = !isProduction
? ['webpack-dev-server/client?http://localhost:' + port,
'webpack/hot/dev-server',
Path.join(__dirname, './src/app/index')]
: [Path.join(__dirname, './src/app/index')];
// ------------------------------------------
// Bundle output
// ------------------------------------------
webpackConfig.output = {
path: Path.join(__dirname, './dist'),
filename: jsOutputPath,
};
// ------------------------------------------
// Devtool
// ------------------------------------------
webpackConfig.devtool = isProduction ? 'source-map' : 'cheap-eval-source-map';
// ------------------------------------------
// Module
// ------------------------------------------
isProduction
? webpackConfig.module.loaders.push({
test: /\.scss$/,
loader: ExtractSASS.extract(['css', 'sass']),
})
: webpackConfig.module.loaders.push({
test: /\.scss$/,
loaders: ['style', 'css', 'sass'],
});
// ------------------------------------------
// Plugins
// ------------------------------------------
isProduction
? webpackConfig.plugins.push(
new Webpack.optimize.OccurenceOrderPlugin(),
new Webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false,
},
}),
ExtractSASS
)
: webpackConfig.plugins.push(
new Webpack.HotModuleReplacementPlugin()
);
// ------------------------------------------
// Development server
// ------------------------------------------
if (!isProduction) {
webpackConfig.devServer = {
contentBase: Path.join(__dirname, './'),
hot: true,
port: port,
inline: true,
progress: true,
historyApiFallback: true,
};
}
module.exports = webpackConfig;