-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
executable file
·123 lines (104 loc) · 3.04 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
121
122
123
/* eslint-disable no-var,prefer-template,vars-on-top,func-style */
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
// var WebpackCleanupPlugin = require('webpack-cleanup-plugin');
var path = require('path');
var loaders = [];
loaders.push({
test: /\.jsx?$/,
exclude: /(node_modules|public)/,
loader: 'babel',
query: {
presets: ['es2015', 'react'],
plugins: ['transform-runtime', 'transform-decorators-legacy', 'transform-class-properties'],
}
});
loaders.push({
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000'
});
loaders.push({
test: /\.scss$/,
exclude: /(node_modules|public)/,
loader: ExtractTextPlugin.extract('style', 'css-raw-loader!sass-loader!postcss-loader')
});
loaders.push({
test: /\.json$/,
loader: 'json'
});
loaders.push({
test: /sinon\.js$/, loader: 'imports?define=>false,require=>false'
});
var config = {
resolve: {
root: path.resolve(__dirname),
alias: {
sinon: 'sinon/pkg/sinon'
},
extensions: ['', '.js', '.jsx']
},
output: {
path: path.join(__dirname, 'public'),
filename: '/js/[name].min.js',
publicPath: ''
},
module: {
loaders
},
plugins: [
new HtmlWebpackPlugin({
template: './src/template.html',
title: 'Gone Busy Sample React App',
filename: 'index.html'
})
]
};
if (process.env.NODE_ENV === 'production') {
config.entry = [
'./src/js/main.js'
];
// config.plugins.push(new WebpackCleanupPlugin()),
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true,
drop_console: true,
drop_debugger: true
}
}));
config.plugins.push(new webpack.optimize.OccurrenceOrderPlugin());
config.plugins.push(new webpack.optimize.DedupePlugin());
} else {
config.entry = [
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
'./src/js/main.js'
];
config.debug = true;
config.devtool = 'source-map';
config.devServer = {
contentBase: './public',
// do not print bundle build stats
noInfo: true,
compress: true,
// enable HMR
hot: true,
// embed the webpack-dev-server runtime into the bundle
inline: true,
// serve index.html in place of 404 responses to allow HTML5 history
historyApiFallback: true,
port: '8080',
host: 'localhost',
stats: { colors: true },
proxy: {
'/api/**': { target: 'http://localhost:4000', secure: false }
}
};
config.plugins.push(new webpack.NoErrorsPlugin());
config.plugins.push(new webpack.HotModuleReplacementPlugin());
}
config.plugins.push(new ExtractTextPlugin('/css/main.css', {
allChunks: true,
}));
module.exports = config;