-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add implementation from PrairieLearn/PrairieLearn (#1)
* Add implementation from PrairieLearn/PrairieLearn Derives from PrairieLearn/PrairieLearn#9900 * remove unnecessary eslint ignore * Remove unused EXCALIDRAW_ASSET_PATH We are bundling all necessary assets into JS/CSS so that we no longer need to statically serve an `excalidraw-dist/`. In case of a package upgrade in the future breaking this contract, we could either point the URL to a non-existent path to catch errors or let it fall back to the default unpkg mirror. We choose the latter.
- Loading branch information
1 parent
b155c0e
commit fd37afb
Showing
6 changed files
with
1,831 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dist | ||
node_modules | ||
*.tgz | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { promises } from 'fs'; | ||
|
||
import * as esbuild from 'esbuild'; | ||
|
||
/* Export and embed JSON as JS */ | ||
const JSONLoader = { | ||
name: 'json-loader', | ||
setup({ onLoad }) { | ||
onLoad({ filter: /\.json$/ }, async (args) => { | ||
const text = await promises.readFile(args.path, 'utf8'); | ||
return { contents: `export default ${text}`, loader: 'js' }; | ||
}); | ||
}, | ||
}; | ||
|
||
const TextReplacer = ({ include, pattern, loader }) => ({ | ||
name: 'text-replacer', | ||
setup({ onLoad }) { | ||
onLoad({ filter: include }, async (args) => { | ||
let contents = await promises.readFile(args.path, 'utf-8'); | ||
for (const [from, to] of pattern) { | ||
contents = contents.replaceAll(from, to); | ||
} | ||
return { contents, loader }; | ||
}); | ||
}, | ||
}); | ||
|
||
await esbuild.build({ | ||
entryPoints: ['./src/index.js'], | ||
outdir: './dist', | ||
bundle: true, | ||
splitting: true, | ||
minify: true, | ||
format: 'esm', | ||
define: { | ||
'process.env.IS_PREACT': 'false', | ||
}, | ||
plugins: [ | ||
JSONLoader, | ||
TextReplacer({ | ||
include: /.js$/, | ||
loader: 'js', | ||
pattern: [ | ||
/* Prevent bootstrap style from hijacking visibility | ||
* https://github.com/excalidraw/excalidraw/issues/3825 */ | ||
['dropdown-menu', 'ex-dropdown-menu'], | ||
], | ||
}), | ||
], | ||
}); | ||
|
||
await esbuild.build({ | ||
entryPoints: ['./src/index.css'], | ||
outdir: './dist', | ||
bundle: true, | ||
minify: true, | ||
loader: { '.woff2': 'dataurl' }, | ||
plugins: [ | ||
TextReplacer({ | ||
include: /.css$/, | ||
loader: 'css', | ||
pattern: [ | ||
/* Prevent bootstrap style from hijacking visibility | ||
* https://github.com/excalidraw/excalidraw/issues/3825 */ | ||
['.dropdown-menu', '.ex-dropdown-menu'], | ||
], | ||
}), | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "@prairielearn/excalidraw-builds", | ||
"type": "module", | ||
"version": "1.0.0", | ||
"description": "Excalidraw bundled with React", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"files": ["dist"], | ||
"repository": "[email protected]:PrairieLearn/excalidraw-builds.git", | ||
"scripts": { | ||
"build": "node esbuild.config.js" | ||
}, | ||
"devDependencies": { | ||
"@excalidraw/excalidraw": "0.17.1-2f9526d", | ||
"react": "18.3.1", | ||
"react-dom": "18.3.1", | ||
"esbuild": "^0.21.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import '@excalidraw/excalidraw/index.css'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom/client'; | ||
|
||
import * as ExcalidrawLib from '@excalidraw/excalidraw'; | ||
|
||
export { React, ReactDOM, ExcalidrawLib }; |
Oops, something went wrong.