Skip to content

Commit

Permalink
build: use esbuild to build react apps
Browse files Browse the repository at this point in the history
  • Loading branch information
cnblogs-dudu committed Dec 15, 2023
1 parent f630263 commit c78130d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 78 deletions.
32 changes: 30 additions & 2 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import esbuild from 'esbuild'
import copyPluginPkg from '@sprout2000/esbuild-copy-plugin'
import { lessLoader } from 'esbuild-plugin-less'
import * as process from 'node:process'

const { copyPlugin } = copyPluginPkg
Expand All @@ -8,7 +9,7 @@ const OUT_DIR = 'dist'

const defaultOptions = {
format: 'cjs',
resolveExtensions: ['.ts', '.js', '.mjs'],
resolveExtensions: ['.ts', '.js', '.mjs', '.tsx'],
bundle: true,
sourcemap: !isProduction,
minify: isProduction,
Expand Down Expand Up @@ -44,6 +45,10 @@ async function buildExtension() {
src: 'node_modules/sequelize',
dest: `${OUT_DIR}/node_modules/sequelize`,
}),
copyPlugin({
src: 'node_modules/@fluentui/font-icons-mdl2/fonts/',
dest: `${OUT_DIR}/assets/fonts`,
}),
copyPlugin({
src: 'src/wasm/rs_bg.wasm',
dest: `${OUT_DIR}/rs_bg.wasm`,
Expand All @@ -65,4 +70,27 @@ async function buildMarkdownItPlugins() {
await esbuild.build(options)
}

await Promise.allSettled([buildExtension(), buildMarkdownItPlugins()])
async function buildUI(...apps) {
for (const app of apps) {
const options = {
...defaultOptions,
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
tsconfig: './ui/tsconfig.json',
entryPoints: [`./ui/${app}/index.tsx`],
outdir: `${OUT_DIR}/assets/ui/${app}`,
plugins: [
lessLoader(),
copyPlugin({
src: `ui/${app}/index.html`,
dest: `${OUT_DIR}/assets/ui/${app}/index.html`,
}),
],
}

await esbuild.build(options)
}
}

await Promise.allSettled([buildExtension(), buildMarkdownItPlugins(), buildUI('ing', 'post-cfg')])
Loading

0 comments on commit c78130d

Please sign in to comment.