-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.dev.js
executable file
·101 lines (95 loc) · 2.79 KB
/
esbuild.dev.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
import 'dotenv/config';
import path from 'path';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import express from 'express';
import esbuild from 'esbuild';
import mdx from '@mdx-js/esbuild';
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';
import rehypeSlug from 'rehype-slug';
import rehypePrism from 'rehype-prism-plus';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import remarkFrontmatter from 'remark-frontmatter';
import remarkGfm from 'remark-gfm';
import remarkMdxFrontmatter from 'remark-mdx-frontmatter';
import remarkEmbedImages from 'remark-embed-images';
// import { remarkMdxCodeMeta } from 'remark-mdx-code-meta';
import stylePlugin from 'esbuild-style-plugin';
import svgrPlugin from 'esbuild-plugin-svgr';
const dirName = dirname(fileURLToPath(import.meta.url));
const startTime = new Date().getTime();
esbuild
.serve(
{
host: 'localhost',
// servedir: 'public',
port: 4000,
},
{
logLevel: 'info',
entryPoints: [path.resolve(dirName, 'src/index.tsx')],
format: 'esm',
target: ['es6'],
bundle: true,
sourcemap: true,
color: true,
// minify: true,
// splitting: true,
// outdir: path.resolve(dirName, 'public'),
outfile: path.resolve(dirName, 'public/index.js'),
loader: {
'.png': 'dataurl',
'.jpg': 'dataurl',
'.jpeg': 'dataurl',
'.gif': 'dataurl',
},
plugins: [
stylePlugin({
postcssConfigFile: path.resolve(dirName, 'postcss.config.js'),
}),
svgrPlugin(),
mdx({
development: true,
remarkPlugins: [
remarkMath,
remarkGfm,
remarkFrontmatter,
remarkMdxFrontmatter,
remarkEmbedImages,
],
rehypePlugins: [
rehypeKatex,
rehypePrism,
rehypeSlug,
[
rehypeAutolinkHeadings,
{ behavior: 'append', test: ['h2', 'h3', 'h4', 'h5', 'h6'] },
],
],
}),
],
define: {
'process.env.GMapAPIKey': `'${process.env.GMapAPIKey}'`,
'process.env.GATagID': `'${process.env.GATagID}'`,
},
},
)
.then(server => {
const { host, port } = server;
const app = express();
app.get('/*', function (req, res) {
res.sendFile(path.resolve(dirName, 'public/index.html'), function (err) {
if (err) {
res.status(500).send(err);
}
});
});
app.listen(3000);
const endTime = new Date().getTime();
const timeDiff = endTime - startTime;
console.log(
`😽 Build successfully in ${timeDiff} ms, development server started at: \n👉 http://${host}:3000`,
);
})
.catch(() => process.exit(1));