Skip to content

Commit 9a6f65a

Browse files
committed
(enh) add example to rollup build against Node/esm modules
1 parent 17cfb87 commit 9a6f65a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

test/builds/node_build_as_esm.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import hljs from "../../build/es/index.js";
2+
3+
const API = [
4+
"getLanguage",
5+
"registerLanguage",
6+
"highlight",
7+
"highlightAuto",
8+
"highlightAll",
9+
"highlightElement",
10+
];
11+
12+
const assert = (f, msg) => {
13+
if (!f()) {
14+
console.error(msg);
15+
process.exit(1);
16+
}
17+
};
18+
const keys = Object.keys(hljs);
19+
20+
API.forEach((n) => {
21+
assert((_) => keys.includes(n), `API should include ${n}`);
22+
});
23+
24+
console.log("Pass: browser build works with Node.js just fine.");
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// rollup.config.js
2+
import commonjs from "@rollup/plugin-commonjs";
3+
4+
export default {
5+
input: "test/builds/node_build_as_esm.mjs",
6+
output: {
7+
file: "build/bundle.js",
8+
format: "iife",
9+
},
10+
plugins: [
11+
commonjs({
12+
include: "build/**", // Default: undefined
13+
exclude: ["node_modules/**"], // Default: undefined
14+
}),
15+
],
16+
};

0 commit comments

Comments
 (0)