-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.babel.js
More file actions
125 lines (107 loc) · 2.58 KB
/
webpack.config.babel.js
File metadata and controls
125 lines (107 loc) · 2.58 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
118
119
120
121
122
123
124
125
import path from 'path';
import webpack from 'webpack';
import merge from 'webpack-merge';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import CleanPlugin from 'clean-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
const HOST = process.env.HOST;
const PORT = process.env.PORT;
const TARGET = process.env.NODE_ENV;
const PATHS = {
root: path.join(__dirname, '.'),
src: path.join(__dirname, 'src'),
dist: path.join(__dirname, 'dist')
};
process.env.BABEL_ENV = TARGET;
const common = {
entry: {
['js/bundle.js']: [
`webpack-hot-middleware/client?path=http://${HOST}:${PORT}/__webpack_hmr&reload=true`,
`${PATHS.src}/main.js`
],
},
resolve: {
moduleDirectories: [PATHS.src, 'node_modules'],
extensions: ['', '.js', 'json']
},
output: {
path: PATHS.dist,
filename: '[name]'
},
module: {
loaders: [
{
test: /\.js$/,
include: PATHS.src,
exclude: /node_modules/,
loaders: ['babel-loader?cacheDirectory']
}
]
},
sassLoader: {
includePaths: [path.join(PATHS.src, 'sass')]
},
plugins: [
new CleanPlugin([PATHS.dist], {
root: PATHS.root
}),
new HtmlWebpackPlugin({
title: 'React Booster Boilerplate',
filename: path.join(PATHS.dist, 'index.html')
})
]
};
const development = {
devtool: 'inline-source-map',
output: {
publicPath: `http://${HOST}:${PORT}/`
},
module: {
loaders: [
{
test: /\.s?css$/,
include: PATHS.src,
loaders: ['style-loader', 'css-loader', 'sass-loader']
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
};
const dist = {
output: {
publicPath: '/'
},
module: {
loaders: [
{
test: /\.s?css$/,
include: PATHS.src,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!sass-loader')
}
]
},
plugins: [
new ExtractTextPlugin('./css/bundle.css'),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
mangle: false,
sourcemap: false,
compress: { drop_console: true } // eslint-disable-line camelcase
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
]
};
let envConfig;
if ( TARGET === 'development' || TARGET === 'test' || !TARGET ) {
envConfig = development;
} else if ( TARGET === 'production' ) {
envConfig = dist;
}
export default merge(common, envConfig);