build.mjs (1.3 KB)


 1 #!/usr/bin/env node
 2 // Build script to bundle CodeMirror for offline use
 3 //
 4 // Usage:
 5 //	cd vendor
 6 //	npm install
 7 //	npm run build
 8 //
 9 // This will regenerate ../js/codemirror-bundle.js
10 
11 import * as esbuild from 'esbuild';
12 import { fileURLToPath } from 'url';
13 import { dirname, join } from 'path';
14 
15 const __dirname = dirname(fileURLToPath(import.meta.url));
16 
17 await esbuild.build({
18 	stdin: {
19 		contents: `
20 			export {EditorView, keymap, placeholder, lineNumbers, Decoration} from "@codemirror/view";
21 			export {EditorState, Compartment} from "@codemirror/state";
22 			export {defaultKeymap, indentWithTab, undo, redo, undoDepth, redoDepth, history, historyKeymap} from "@codemirror/commands";
23 			export {closeBrackets, closeBracketsKeymap} from "@codemirror/autocomplete";
24 			export {html} from "@codemirror/lang-html";
25 			export {githubDark} from "@fsegurai/codemirror-theme-github-dark";
26 			export {indentUnit} from "@codemirror/language";
27 			export {search, searchKeymap, closeSearchPanel, openSearchPanel} from "@codemirror/search";
28 		`,
29 		resolveDir: __dirname,
30 		loader: 'js',
31 	},
32 	bundle: true,
33 	format: 'esm',
34 	outfile: join(__dirname, '..', 'js', 'codemirror-bundle.js'),
35 	minify: true,
36 	target: ['es2020'],
37 });
38 
39 console.log('✓ CodeMirror bundle created: ../js/codemirror-bundle.js');