-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
158 lines (148 loc) · 3.59 KB
/
webpack.config.js
File metadata and controls
158 lines (148 loc) · 3.59 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
require('dotenv').config()
const path = require('path')
const webpack = require('webpack')
const WorkboxPlugin = require('workbox-webpack-plugin')
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin')
const MomentLocalesPlugin = require('moment-locales-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const ManifestPlugin = require('webpack-manifest-plugin')
const CONSTANTS = [
'NODE_ENV',
'HOSTNAME',
'API_VERSION',
'SESSION_SECRET',
'COOKIE_SECRET',
'RADPLAID_CLIENT_ID',
'STRIPE_PUBLISHABLE_KEY',
'BASE_CLIENT_URL',
'BASE_SERVER_URL',
'ASSET_URL',
'GA_ID',
'GA_CONVERSION_ID',
'DATE_FORMAT',
'APPLE_APP_ID',
'FACEBOOK_APP_ID',
'AUTHO_CLIENT_ID',
'SOUNDCLOUD_CLIENT_ID',
'KICKBOX_APP_CODE',
'LOCATION_ACCURACY',
'MAPBOX_ACCESS_TOKEN',
'MIXPANEL_KEY',
'SENTRY_KEY'
]
const getEnv = () => {
let env = {}
CONSTANTS.forEach((key) => {
env[key] = JSON.stringify(process.env[key])
})
return env
}
module.exports = {
context: __dirname,
mode: 'development',
devtool: 'cheap-module-eval-source-map',
devServer: {
port: 5319,
contentBase: './public',
hotOnly: true,
},
target: 'web',
entry: {
main: './src/app/client.jsx',
head: './src/app/head.js',
simple: './src/app/simple.js',
analytics: './src/app/helpers/analytics.jsx'
},
output: {
path: path.join(__dirname, '/public/js'),
publicPath: '/js/',
filename: '[name].[hash].js',
chunkFilename: '[name].[hash].js',
pathinfo: false,
},
module: {
rules: [{
test: /\.jsx?$/,
loader: 'babel-loader?cacheDirectory',
exclude: /(node_modules)/,
query: {
presets: [
'env',
'react',
'stage-0'
]
}
}]
},
resolve: {
symlinks: false
},
optimization: {
runtimeChunk: false,
removeAvailableModules: false,
removeEmptyChunks: false,
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 150000,
// chunks: 'async',
// minSize: 30000,
maxSize: 0,
minChunks: 1,
maxAsyncRequests: 5,
// maxInitialRequests: 3,
automaticNameDelimiter: '-',
name: true,
cacheGroups: {
// vendors: {
// chunks: 'initial',
// name: 'vendor',
// test: /[\\/]node_modules[\\/]/,
// priority: -10
// },
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
// npm package names are URL-safe, but some servers don't like @ symbols
return `${packageName.replace('@', '')}`;
}
},
default: {
minChunks: Infinity,
priority: -20,
reuseExistingChunk: true
}
}
}
},
plugins: [
new CleanWebpackPlugin([ 'public/js/**/*' ]),
new ManifestPlugin(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.HotModuleReplacementPlugin(),
new MomentLocalesPlugin({
localesToKeep: [ 'en' ]
}),
new HardSourceWebpackPlugin({
cachePrune: {
// Caches younger than `maxAge` are not considered for deletion. They must
// be at least this (default: 2 days) old in milliseconds.
maxAge: 2 * 24 * 60 * 60 * 1000,
// All caches together must be larger than `sizeThreshold` before any
// caches will be deleted. Together they must be at least this
// (default: 50 MB) big in bytes.
sizeThreshold: 500 * 1024 * 1024
}
}),
new webpack.DefinePlugin({
'process.env': getEnv()
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new WorkboxPlugin.InjectManifest({
swSrc: './src/app/service-worker.js'
})
]
};