summaryrefslogtreecommitdiff
path: root/docs/src/docusaurus-tree-sitter-plugin
diff options
context:
space:
mode:
Diffstat (limited to 'docs/src/docusaurus-tree-sitter-plugin')
-rw-r--r--docs/src/docusaurus-tree-sitter-plugin/index.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/docs/src/docusaurus-tree-sitter-plugin/index.js b/docs/src/docusaurus-tree-sitter-plugin/index.js
new file mode 100644
index 0000000..7803a9e
--- /dev/null
+++ b/docs/src/docusaurus-tree-sitter-plugin/index.js
@@ -0,0 +1,39 @@
+module.exports = function () {
+ return {
+ configureWebpack(config, isServer) {
+ let rules = [];
+
+ // Tree-sitter is only used for client-side code.
+ // Don't try to load it on the server.
+ if (isServer) {
+ rules.push({
+ test: /web-tree-sitter/,
+ loader: "null-loader",
+ });
+ } else {
+ // web-tree-sitter has a hard-coded path to tree-sitter.wasm,
+ // (see https://github.com/tree-sitter/tree-sitter/issues/559)
+ // which some browsers treat as absolute and others as relative.
+ // This breaks everything. Rewrite it to always use an absolute path.
+ rules.push({
+ test: /tree-sitter\.js$/,
+ loader: "string-replace-loader",
+ options: {
+ search: '"tree-sitter.wasm"',
+ replace: '"/tree-sitter.wasm"',
+ strict: true,
+ },
+ });
+ }
+
+ return {
+ // web-tree-sitter tries to import "fs", which can be ignored.
+ // https://github.com/tree-sitter/tree-sitter/issues/466
+ node: {
+ fs: "empty",
+ },
+ module: { rules },
+ };
+ },
+ };
+};