-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
227 lines (211 loc) · 6.86 KB
/
vue.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
/* eslint-disable no-console,no-param-reassign */
const path = require('path');
// to import only during build
const PurgecssPlugin = process.env.ENV ? '' : require('purgecss-webpack-plugin');
const glob = process.env.ENV ? '' : require('glob-all');
const { appid } = require('./kubeconfig.json');
const { name } = require('./package.json');
// eslint-disable-next-line
const metric = name === 'webmd-vuejs-metrics' ? require('./src/js/directives/ssr-directive.es6') : require('webmd-vuejs-metrics/src/js/directives/ssr-directive.es6');
const versions = require('./versions.json');
const isProd = process.env.NODE_ENV === 'production';
const errorUrl = 'https://www.webmd.com/500';
const publicPath = isProd ? `/static_vue/${appid}/` : '/';
const outputDir = `dist/${appid}/`;
const purgeCSSEnabledApps = [/091e9c5e81654093/, /091e9c5e81655838/, /091e9c5e813efa75/, /091e9c5e813f0e53/, /091e9c5e813ef48f/, /091e9c5e8140502f/, /091e9c5e813f2bfb/, /091e9c5e813f2bf9/, /091e9c5e81e4870f/, /091e9c5e81e4bc92/, /091e9c5e81e52376/, /091e9c5e81e52a7c/];
const plugins = isProd && purgeCSSEnabledApps.some(rx => rx.test(appid)) && !process.env.ENV ? [
new PurgecssPlugin({
paths: glob.sync(['**/*.vue', '**/*.html', '**/*.es6.js']),
defaultExtractor(content) {
const contentWithoutStyleBlocks = content.replace(
/<style[^]+?<\/style>/gi,
'',
);
return (
contentWithoutStyleBlocks.match(
/[A-Za-z0-9-_/:]*[A-Za-z0-9-_/]+/g,
) || []
);
},
safelist: {
standard: [
/-(leave|enter|appear)(|-(to|from|active))$/,
/^(?!(|.*?:)cursor-move).+-move$/,
/^router-link(|-exact)-active$/,
/data-v-.*/,
/data-mode*/,
/btn-.*/,
/webmd-pagination-*/,
/webmd-button-*/,
/webmd-icon-*/,
/vue-video-container/,
],
deep: [/global-nav/, /ad$/, /ad-.*/, /webmd-checkbox/, /amp-.*/],
greedy: [],
keyframes: [],
variables: [],
},
/*
*removes vitals css since everything is wrapped in material class.
* "material" is a blacklisted word. Do NOT use it in your CSS.
*/
blocklist: [/material/],
})] : [];
module.exports = {
runtimeCompiler: true,
css: {
loaderOptions: {
sass: {
data: '@import "webmd-elements/packages/theme-chalk/src/typography.scss";',
},
},
// comment out below line to make the local build faster
sourceMap: true,
},
publicPath,
outputDir,
lintOnSave: false,
transpileDependencies: [/\.jsx/, /\.es6\.js/, /pagedata.js/, /store.js/, /router.js/, /webmd-html2canvas/, /css-line-break/],
// comment out below line to make the local build faster
productionSourceMap: true,
pluginOptions: {
ssr: {
host: '0.0.0.0',
// Specify public file paths to disable resource prefetch hints for
shouldNotPrefetch: [],
// Specify public file paths to disable resource preload hints for
shouldNotPreload: [],
directives: {
metric,
},
extendContext: (req, res, process) => ({
pagedata: {
meta: {},
omniture: {
s_account: 'webmddev',
},
jsonld: {},
startTime: 0,
},
url: req.url,
res,
fullUrl: req.url,
env: process.env.WEBMD_ENV,
host: (req.headers || {}).host,
appid,
staticPublicPath: publicPath,
outputDir,
}),
criticalCSS: false,
applyDefaultServer: false,
extendServer: ({
app,
express,
}) => {
// eslint-disable-next-line no-unused-vars
const webLog = (req, res, next) => {
if (req.url !== '/health') {
const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
const IP = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
const method = 'GET';
console.log(`${IP}\t${method}\t${fullUrl}`);
}
// ::1 GET http://localhost:8080/
next();
};
const allowCors = (req, res, next) => {
const { hostname } = req;
const whiteListedHosts = ['webmd.com', 'vitals.com', 'wbmdstatic.com', 'univadis.com', 'medscape.com'];
if (whiteListedHosts.some(host => hostname.includes(host))) {
res.setHeader('Access-Control-Allow-Origin', '*');
}
next();
};
app.use(allowCors);
app.get('/health', (req, res) => res.send('OK'));
app.use(webLog);
app.get('/versions', (req, res) => {
res.header('Content-Type', 'application/json');
res.send(JSON.stringify(versions, null, 2));
});
app.use('/static_vue', express.static(path.resolve(__dirname, './dist'), {
maxAge: isProd ? 300 : 0,
index: false,
}));
},
renderToString: ({
// eslint-disable-next-line no-unused-vars
context,
err,
renderedHtml,
// eslint-disable-next-line no-unused-vars
req,
res,
}) => {
/**
* Below code will only execute if the response is not handled during SSR
* through the context 'res' provided above.
*/
if (!res.headersSent) {
if (err) {
if (process.env.ENV !== 'production') {
res.status(500)
.end(`<html><body><pre>${err.stack}</pre></body></html>`);
} else {
res.redirect(302, errorUrl);
}
} else {
const currentTime = new Date();
const epocTimeStamp = Math.floor(currentTime / 1000);
const gmt = currentTime.toGMTString();
res.set('ETag', epocTimeStamp);
res.set('Last-Modified', gmt);
res.set('Cache-Control', 'max-age=120, s-maxage=300, must-revalidate, stale-while-revalidate=30, stale-if-error=43200, public');
res.end(renderedHtml);
}
}
},
skipRequests: req => req.originalUrl === '/metrics' || req.originalUrl === '/health' || req.originalUrl === '/__webpack_hmr' || req.originalUrl === '/versions' || req.originalUrl === '/static_vue',
nodeExternalsWhitelist: [/\.css$/, /\.vue$/, /src\/store$/, /src\/router$/, /util\/pagedata$/, /\.es6$/, /lib\/dfp$/, /webmd-html2canvas/, /css-line-break/],
distPath: path.resolve(__dirname, `./dist/${appid}`),
templatePath: path.resolve(__dirname, `./dist/${appid}/index.template.html`),
},
},
chainWebpack: (config) => {
config
.devtool('source-map');
/*
* adding timestamp to contenthash of the output css chunks
* because change to purgecss config doesn't result
* in contenthash change
* https://github.com/FullHuman/purgecss-webpack-plugin/issues/65
*/
if (config.plugins.has('extract-css')) {
config
.plugin('extract-css')
.tap((args) => {
args[0].filename = args[0].filename.replace('[name]', `[name]-${Date.now()}`);
args[0].chunkFilename = args[0].chunkFilename.replace('[name]', `[name]-${Date.now()}`);
return args;
});
}
},
configureWebpack: () => ({
resolve: {
// symlinks: false,
},
optimization: {
// eslint-disable-next-line no-nested-ternary
splitChunks: process.env.VUE_CLI_SSR_TARGET === 'server' ? false : !isProd ? undefined : {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/](webmd-elements)[\\/]/,
name: 'webmd-elements',
chunks: 'all',
},
},
},
},
plugins,
}),
};