-
Notifications
You must be signed in to change notification settings - Fork 0
/
web-dev-server.config.mjs
64 lines (53 loc) · 1.89 KB
/
web-dev-server.config.mjs
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
// import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
import { fileURLToPath } from 'url';
import { fromRollup } from '@web/dev-server-rollup';
import rollupReplace from '@rollup/plugin-replace';
import rollupCommonjs from '@rollup/plugin-commonjs';
import { esbuildPlugin } from '@web/dev-server-esbuild';
const replace = fromRollup(rollupReplace);
const commonjs = fromRollup(rollupCommonjs);
/** Use Hot Module replacement by adding --hmr to the start command */
const hmr = process.argv.includes('--hmr');
export const makeConfig = (
appIndex,
rootDir = undefined,
) => Object.assign({
open: false,
watch: !hmr,
/** Resolve bare module imports */
nodeResolve: {
exportConditions: ['browser', 'development'],
browser: true,
preferBuiltins: false
},
/** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
// esbuildTarget: 'auto'
/** Set appIndex to enable SPA routing */
appIndex,
clearTerminalOnReload: false,
plugins: [
replace({
'process.env.HC_PORT': JSON.stringify(process.env.HC_PORT),
'process.env.HC_ADMIN_PORT': JSON.stringify(process.env.HC_ADMIN_PORT),
delimiters: ['', ''],
}),
commonjs({
include: [
'**/node_modules/tweetnacl/*',
],
}),
/** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
// hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.litElement] }),
// ESBuild also handles TypeScript compilation and MIMEtype config
esbuildPlugin({
target: 'auto',
ts: true,
json: true,
jsx: true,
tsx: true,
tsconfig: fileURLToPath(new URL('./tsconfig.json', import.meta.url))
}),
],
// See documentation for all available options
}, rootDir ? { rootDir } : {})
export default /** @type {import('@web/dev-server').DevServerConfig} */ makeConfig("index.html", "./")