This repository was archived by the owner on Dec 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
61 lines (56 loc) · 1.88 KB
/
Copy pathbuild.js
File metadata and controls
61 lines (56 loc) · 1.88 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
const { start } = require('live-server')
const { watch } = require('chokidar')
const { build } = require('esbuild')
const fs = require('fs-extra')
const isDev = process.env.NODE_ENV !== 'production'
/**
* Live Server Params
* @link https://www.npmjs.com/package/live-server#usage-from-node
*/
const serverParams = {
port: 8000, // Set the server port. Defaults to 8080.
root: 'dist', // Set root directory that's being served. Defaults to cwd.
open: true // When false, it won't load your browser by default.
// host: "0.0.0.0", // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP.
// ignore: 'scss,my/templates', // comma-separated string for paths to ignore
// file: "index.html", // When set, serve this file (server root relative) for every 404 (useful for single-page applications)
// wait: 1000, // Waits for all changes, before reloading. Defaults to 0 sec.
// mount: [['/components', './node_modules']], // Mount a directory to a route.
// logLevel: 2, // 0 = errors only, 1 = some, 2 = lots
// middleware: [function(req, res, next) { next(); }] // Takes an array of Connect-compatible middleware that are injected into the server middleware stack
}
/**
* ESBuild Params
* @link https://esbuild.github.io/api/#build-api
*/
const buildParams = {
color: true,
entryPoints: ['src/index.jsx'],
loader: {
'.js': 'jsx',
'.woff': 'dataurl',
'.woff2': 'dataurl',
'.eot': 'dataurl',
'.ttf': 'dataurl',
},
outdir: 'dist',
minify: !isDev,
format: 'cjs',
bundle: true,
sourcemap: true,
logLevel: 'error',
incremental: true
}
; (async () => {
fs.removeSync('dist')
fs.copySync('public', 'dist')
const builder = await build(buildParams)
if (isDev) {
watch('src/**/*', { ignoreInitial: true }).on('all', () => {
builder.rebuild()
})
start(serverParams)
} else {
process.exit(0)
}
})()