-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
247 lines (239 loc) · 6.57 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
const path = require('path')
const webpack = require('webpack')
const moment = require('moment')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const { GenerateSW } = require('workbox-webpack-plugin')
const GitRevisionPlugin = require('git-revision-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const AddAssetPlugin = require('add-asset-webpack-plugin')
const config = require('./config')
const gitRevisionPlugin = new GitRevisionPlugin()
const dotenv = require('dotenv')
dotenv.config()
const ICON_SIZES = [56, 112, 192, 224, 512]
const manifest = () => JSON.stringify({
id: 'sojourner',
short_name: 'Sojourner',
name: `Sojourner - ${config.conference.name} Conference Companion`,
icons: ICON_SIZES.map(size => ({
src: `/assets/sojourner-icon-app-${size}.png`,
sizes: `${size}x${size}`,
type: 'image/png',
purpose: 'maskable any'
})),
start_url: '/',
scope: `https://${config.conference.id}.sojourner.rocks`,
display: 'standalone',
orientation: 'portrait',
background_color: config.colors.primary.base,
theme_color: config.colors.primary.base,
categories: ['utilities', 'education', 'social'],
lang: 'en',
dir: 'ltr',
description: `Sojourner is a ${config.conference.name} conference companion progressive web app (PWA).`,
screenshots: [
{
src: '/screenshots/dashboard.png',
sizes: '563x1218',
type: 'image/png',
label: 'Dashboard'
},
{
src: '/screenshots/devrooms.png',
sizes: '563x1218',
type: 'image/png',
label: 'Tracks'
},
{
src: '/screenshots/events.png',
sizes: '563x1218',
type: 'image/png',
label: 'Track events'
},
{
src: '/screenshots/search.png',
sizes: '563x1218',
type: 'image/png',
label: 'Search'
}
]
}, null, 2)
module.exports = {
context: path.resolve(__dirname, '.'),
entry: './main.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/',
filename: '[name].js',
devtoolModuleFilenameTemplate: info => info.resourcePath.match(/^\.\/\S*?\.vue$/)
? `webpack-generated:///${info.resourcePath}?${info.hash}`
: `webpack-code:///${info.resourcePath}`,
devtoolFallbackModuleFilenameTemplate: 'webpack:///[resource-path]?[hash]'
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
vue$: 'vue/dist/vue.esm.js',
'@': path.resolve(__dirname),
assets: path.resolve(__dirname, 'assets')
}
},
mode: 'development',
stats: {
children: false
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
}
},
{
test: /preload\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
]
},
{
test: /\.css$/,
exclude: /preload\.css$/,
use: [
'vue-style-loader',
'css-loader'
]
},
{
test: /\.(png|jpg|gif|svg)$/,
use: [
{
loader: 'url-loader',
options: {
name: '[path][name].[ext]',
limit: 8192,
esModule: false
}
}
]
},
{
test: /\.(woff|woff2|ttf|eot)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]'
}
}
]
}
]
},
devServer: {
historyApiFallback: true
},
performance: {
hints: false
},
devtool: 'eval-source-map',
plugins: [
new VueLoaderPlugin(),
new CleanWebpackPlugin(),
new CopyWebpackPlugin([
'static/',
'assets/*'
]),
new AddAssetPlugin('assets/manifest.json', manifest),
new webpack.EnvironmentPlugin({
TIMESTAMP: moment().utcOffset('+0100').format('YYYY-MM-DD HH:mm:ss'),
COMMITHASH: gitRevisionPlugin.commithash(),
VERSION: process.env.npm_package_version,
SCHEDULE_INTERVAL: 0,
ROOM_STATE_URL: '',
ROOM_STATE_INTERVAL: 0,
ANALYTICS_URL: '',
SENTRY_DSN: '',
FIREBASE_API_KEY: undefined,
FIREBASE_AUTH_DOMAIN: undefined,
FIREBASE_DATABASE_URL: undefined,
FIREBASE_PROJECT_ID: undefined,
FIREBASE_STORAGE_BUCKET: undefined,
FIREBASE_MESSAGING_SENDER_ID: undefined
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css'
}),
new HtmlWebpackPlugin({
template: 'index.html',
inject: false
}),
new BundleAnalyzerPlugin({
analyzerMode: 'disabled'
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new GenerateSW({
cacheId: 'sojourner',
clientsClaim: true,
skipWaiting: true,
navigateFallback: '/index.html',
exclude: [/\.map$/, /^manifest.*\.js$/, '_redirects', '_headers'],
runtimeCaching: [
{
urlPattern: new RegExp('^https://firebasestorage\\.googleapis\\.com/v0/b/sojourer-web\\.appspot\\.com/o/conferences%2F.*\\.json\\?alt=media$'),
handler: 'StaleWhileRevalidate',
options: {
broadcastUpdate: {
channelName: 'workbox'
}
}
}
]
})
]
}
if (process.env.NODE_ENV === 'test') {
module.exports.devtool = 'inline-source-map'
}
if (process.env.NODE_ENV === 'production') {
module.exports.mode = 'production'
module.exports.output.filename = '[name].[contenthash].js'
module.exports.devtool = 'source-map'
module.exports.optimization = {
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
styles: {
name: 'preload',
test: /preload\.css$/,
chunks: 'all',
enforce: true
},
commons: {
test: /[\\/]node_modules[\\/]/,
chunks: 'all',
name (module) {
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
// npm package names are URL-safe, but some servers don't like @ symbols
return `npm.${packageName.replace('@', '')}`
}
}
}
}
}
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}