summaryrefslogtreecommitdiff
path: root/docs/src/docusaurus-tree-sitter-plugin/index.js
blob: 7803a9e995da12af5e458a74c59da0f2ad223d25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 },
      };
    },
  };
};