Skip to content

Commit 285c03a

Browse files
committed
Add index.browser.mjs
1 parent ff73d54 commit 285c03a

File tree

4 files changed

+83
-483
lines changed

4 files changed

+83
-483
lines changed

packages/mdx/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
"default": "./dist/components.cjs.js"
2929
}
3030
},
31+
"browser": {
32+
"./dist/index.esm.js": "./dist/index.browser.mjs"
33+
},
3134
"scripts": {
3235
"dev": "next",
3336
"build": "rollup -c rollup.config.js",
@@ -50,6 +53,7 @@
5053
"devDependencies": {
5154
"@mdx-js/mdx": "^2.0.0",
5255
"@rollup/plugin-json": "^4.1.0",
56+
"@rollup/plugin-replace": "^4.0.0",
5357
"@types/diff": "^5.0.2",
5458
"@types/node": "^17.0.21",
5559
"@types/node-fetch": "^2.6.1",

packages/mdx/rollup.config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import typescript from "rollup-plugin-typescript2"
77
import path from "path"
88
import json from "@rollup/plugin-json"
99
import del from "rollup-plugin-delete"
10+
import replace from "@rollup/plugin-replace"
11+
// import { terser } from "rollup-plugin-terser"
1012

1113
export default function makeConfig(commandOptions) {
1214
return [
@@ -46,6 +48,35 @@ export default function makeConfig(commandOptions) {
4648
}),
4749
],
4850
},
51+
// for the browser esm we need to replace shiki with shiki/dist/shiki.browser.mjs
52+
// https://github.com/shikijs/shiki/issues/131#issuecomment-1094281851
53+
{
54+
input: `src/index.tsx`,
55+
output: [
56+
{
57+
file: `./dist/index.browser.mjs`,
58+
format: "es",
59+
},
60+
],
61+
// external: ["react"],
62+
plugins: [
63+
replace({
64+
delimiters: ["", ""],
65+
values: {
66+
'"shiki"': JSON.stringify(
67+
"shiki/dist/index.browser.mjs"
68+
),
69+
},
70+
}),
71+
json({ compact: true }),
72+
typescript({
73+
tsconfigOverride: {
74+
compilerOptions: { jsx: "react" },
75+
},
76+
}),
77+
// terser(),
78+
],
79+
},
4980
{
5081
input: `src/components.tsx`,
5182
output: [

packages/mdx/src/highlighter/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export async function highlight({
3333
}
3434
}
3535
if (highlighterPromise === null) {
36+
// TODO add version
3637
setCDN("https://unpkg.com/shiki/")
3738
highlighterPromise = getHighlighter({
3839
theme: theme as IShikiTheme,

0 commit comments

Comments
 (0)