-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathweb-dev-server.config.mjs
More file actions
49 lines (47 loc) · 1.49 KB
/
web-dev-server.config.mjs
File metadata and controls
49 lines (47 loc) · 1.49 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
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import path from 'path';
import fs from 'fs';
export default {
nodeResolve: true,
preserveSymlinks: true,
rootDir: ".",
appIndex: "src/index.html",
open: "/",
middleware: [
// Redirect root to src/index.html
function serveRoot(context, next) {
if (context.url === '/' || context.url === '/index.html') {
context.url = '/src/index.html';
}
return next();
},
// Serve .js files from build/ folder
function serveJsFromBuild(context, next) {
if (context.url.endsWith('.js') || context.url.endsWith('.js.map')) {
const buildPath = path.join(process.cwd(), 'build', path.basename(context.url));
if (fs.existsSync(buildPath)) {
context.url = '/build' + '/' + path.basename(context.url);
}
}
return next();
},
// Serve iframe.html from src/iframe.html
function serveIframe(context, next) {
if (context.url === '/iframe.html') {
context.url = '/src/iframe.html';
}
return next();
},
// Serve /images from src/images
function serveImages(context, next) {
if (context.url.startsWith('/images/')) {
context.url = '/src' + context.url;
}
return next();
}
]
};