-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
117 lines (96 loc) · 2.39 KB
/
Copy pathwebpack.config.js
File metadata and controls
117 lines (96 loc) · 2.39 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
105
106
107
108
109
110
111
112
113
114
115
116
117
const path = require('path');
const webpack = require('webpack');
const HtmlPlugin = require('html-webpack-plugin');
const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const isHot = !isProduction && process.env.NODE_ENV === 'development';
const port = process.env.WEBPACK_PORT || 8080;
function getDevTool() {
if (isProduction) return 'source-map';
return 'eval-source-map';
}
function getModuleLoaders() {
const loaders = [];
loaders.push({
test: /\.(js|jsx)$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
});
if (isProduction) {
loaders.push({
test: /(\.scss|\.css)$/,
loader: ExtractTextPlugin.extract('style', 'css!postcss!sass')
});
}
if (!isProduction) {
loaders.push({
test: /(\.scss|\.css)$/,
loaders: ['style', 'css', 'postcss', 'sass']
});
}
return loaders;
}
function getDevServer() {
if (!isProduction) {
return {
contentBase: path.join(__dirname, 'public'),
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
stats: {
colors: true,
chunks: false
},
host: 'localhost',
port: port
};
}
return null;
}
function getPlugins() {
const plugins = [
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify(process.env.NODE_ENV) }
}),
new HtmlPlugin({
template: 'node_modules/html-webpack-template/index.ejs',
title: 'Voting App',
appMountId: 'root',
inject: false,
mobile: true
})
];
if (isProduction) {
plugins.push(
new ExtractTextPlugin('style.css'),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } })
);
}
if (isHot) {
plugins.push(new webpack.HotModuleReplacementPlugin());
}
return plugins;
}
module.exports = {
devtool: getDevTool(),
entry: {
client: path.join(__dirname, 'src/client.js')
},
output: {
path: path.join(__dirname, 'public'),
filename: '[name].js'
},
devServer: getDevServer(),
module: {
loaders: getModuleLoaders()
},
resolve: {
extensions: ['', '.js', '.jsx', '.scss']
},
postcss: () => [autoprefixer],
plugins: getPlugins()
};