forked from aredotna/ervell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
131 lines (125 loc) · 3.3 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
124
125
126
127
128
129
130
131
const path = require('path');
const webpack = require('webpack');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const WebpackNotifierPlugin = require('webpack-notifier');
const helpers = require('./webpack.helpers.js');
const { NODE_ENV, PORT } = process.env;
const isDevelopment = NODE_ENV === 'development';
const isStaging = NODE_ENV === 'staging';
const isProduction = NODE_ENV === 'production';
const isDeploy = isStaging || isProduction;
const config = {
devtool: 'cheap-module-source-map',
entry: {
webpack: [
'webpack-hot-middleware/client?reload=true',
],
...helpers.getEntrypoints(),
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'public/assets'),
publicPath: '/assets',
sourceMapFilename: '[file].map?[contenthash]',
},
module: {
rules: [
{
test: /\.coffee$/,
exclude: /node_modules/,
loader: 'coffee-loader',
},
{
test: /\.(jade|pug)$/,
exclude: /node_modules/,
loader: 'pug-loader',
options: {
doctype: 'html',
root: __dirname,
},
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
query: {
cacheDirectory: true,
env: {
development: {
presets: ['react-hmre'],
plugins: [
['react-transform', {
transforms: [{
transform: 'react-transform-hmr',
imports: ['react'],
locals: ['module'],
}],
}],
],
},
},
},
},
],
},
{
test: /\.json$/,
exclude: /node_modules/,
loader: 'json-loader',
},
],
},
plugins: [
new FriendlyErrorsWebpackPlugin({
compilationSuccessInfo: {
messages: [`[Ervell] Listening on http://localhost:${PORT} \n`],
},
}),
new ProgressBarPlugin(),
new WebpackNotifierPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(NODE_ENV),
},
}),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
jade: 'jade/runtime.js',
waypoints: 'jquery-waypoints/waypoints.js',
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
minChunks: 10, // lower number for larger "common.js" bundle size
}),
],
resolve: {
alias: {
'jquery.ui.widget': 'blueimp-file-upload/js/vendor/jquery.ui.widget.js',
},
extensions: ['.js', '.jsx', '.json', '.jade', '.coffee'],
modules: [
'node_modules',
],
symlinks: false,
},
externals: {
request: 'request',
},
};
if (isDevelopment) {
config.plugins.push(new webpack.HotModuleReplacementPlugin());
// Staging
} else if (isDeploy) {
config.devtool = '#source-map';
// Prod
if (isProduction) {
config.plugins.push(new webpack.optimize.UglifyJsPlugin({ sourceMap: true }));
}
}
module.exports = config;