diff options
author | Sebastian <sebasjm@gmail.com> | 2023-04-24 10:56:45 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-04-24 11:57:18 -0300 |
commit | ebf91aef1d4bde5373ff689daa80c6bf9fe3167b (patch) | |
tree | 7bbddfc5e13cf627a446d3a4ec4fb64aecf77a7f /packages/web-util/build.mjs | |
parent | a8681035b40f227c2c3713a7d8f5e2d0e59ba699 (diff) |
build tools
Diffstat (limited to 'packages/web-util/build.mjs')
-rwxr-xr-x | packages/web-util/build.mjs | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/packages/web-util/build.mjs b/packages/web-util/build.mjs index 6e20b8b92..8e74f69c7 100755 --- a/packages/web-util/build.mjs +++ b/packages/web-util/build.mjs @@ -65,6 +65,35 @@ const buildConfigBase = { }, } +/** + * Build time libraries, under node runtime + */ +const buildConfigBuild = { + ...buildConfigBase, + entryPoints: ["src/index.build.ts"], + outExtension: { + '.js': '.mjs' + }, + format: 'esm', + platform: 'node', + external: ["esbuild"], + // https://github.com/evanw/esbuild/issues/1921 + // How to fix "Dynamic require of "os" is not supported" + // esbuild cannot convert external "static" commonjs require statements to static esm imports + banner: { + js: ` + import { fileURLToPath } from 'url'; + import { createRequire as topLevelCreateRequire } from 'module'; + const require = topLevelCreateRequire(import.meta.url); + const __filename = fileURLToPath(import.meta.url); + const __dirname = path.dirname(__filename); +` + }, +}; + +/** + * Development libraries, under node runtime + */ const buildConfigNode = { ...buildConfigBase, entryPoints: ["src/index.node.ts", "src/cli.ts"], @@ -76,6 +105,9 @@ const buildConfigNode = { external: ["preact"], }; +/** + * Support libraries, under browser runtime + */ const buildConfigBrowser = { ...buildConfigBase, entryPoints: ["src/tests/mock.ts", "src/tests/swr.ts", "src/index.browser.ts", "src/live-reload.ts", 'src/stories.tsx'], @@ -89,7 +121,7 @@ const buildConfigBrowser = { jsxFragment: 'Fragment', }; -[buildConfigNode, buildConfigBrowser].forEach((config) => { +[buildConfigNode, buildConfigBrowser, buildConfigBuild].forEach((config) => { esbuild .build(config) .catch((e) => { |