Skip to content

Commit

Permalink
build: separate browser and NodeJS versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ogonkov committed Oct 10, 2024
1 parent 65cb9ba commit 2f2e198
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 13 deletions.
43 changes: 34 additions & 9 deletions esbuild/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,33 @@ const common = {
};

(async () => {
const runtime = await esbuild.build({
...common,
const runtimeCommon = {
entryPoints: ['src/runtime/index.ts'],
outfile: 'build/runtime/index.js',
minify: true,
loader: {
'.svg': 'text',
'.ttf': 'file',
'.woff': 'file',
'.woff2': 'file',
},
plugins: [inlineScss()],
};

const runtime = await esbuild.build({
...common,
...runtimeCommon,
outfile: 'build/runtime/index-node.js',
minify: true,
metafile: true,
});

esbuild.build({
...common,
...runtimeCommon,
outfile: 'build/runtime/index.js',
external: ['katex'],
platform: 'neutral',
});

esbuild.build({
...common,
entryPoints: ['src/react/index.ts'],
Expand All @@ -38,11 +50,7 @@ const common = {
external: ['react'],
});

esbuild.build({
...common,
entryPoints: ['src/plugin/index.ts'],
outfile: 'build/plugin/index.js',
platform: 'node',
const pluginCommon = {
external: ['markdown-it', 'node:*'],
define: {
PACKAGE: JSON.stringify(require('../package.json').name),
Expand All @@ -52,5 +60,22 @@ const common = {
.map((file) => file.replace(/^runtime\//, '')),
),
},
};

esbuild.build({
...common,
...pluginCommon,
entryPoints: ['src/plugin/index.ts'],
outfile: 'build/plugin/index.js',
platform: 'neutral',
external: [...pluginCommon.external, 'katex'],
});

esbuild.build({
...common,
...pluginCommon,
entryPoints: ['src/plugin/index-node.ts'],
outfile: 'build/plugin/index-node.js',
platform: 'node',
});
})();
30 changes: 26 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,35 @@
"main": "build/plugin/index.js",
"types": "build/plugin/index.d.ts",
"exports": {
".": "./build/plugin/index.js",
"./plugin": "./build/plugin/index.js",
"./runtime": "./build/runtime/index.js",
"./runtime/styles": "./build/runtime/index.css",
".": {
"node": "./build/plugin/index-node.js",
"default": "./build/plugin/index.js"
},
"./plugin": {
"node": "./build/plugin/index-node.js",
"default": "./build/plugin/index.js"
},
"./runtime": {
"node": "./build/runtime/index-node.js",
"default": "./build/runtime/index.js"
},
"./runtime/styles": "./build/runtime/index-node.css",
"./react": "./build/react/index.js",
"./hooks": "./build/react/index.js"
},
"typesVersions": {
"*": {
"index.d.ts": [
"./build/plugin/index.d.ts"
],
"plugin": [
"./build/plugin/index.d.ts"
],
"runtime": [
"./build/runtime/index.d.ts"
]
}
},
"scripts": {
"build": "run-p build:*",
"build:js": "./esbuild/build.js",
Expand Down

0 comments on commit 2f2e198

Please sign in to comment.