@tooltify/integration-rspack 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +9 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // index.ts
2
+ import fs from "fs";
2
3
  import path from "path";
3
4
  import { fileURLToPath } from "url";
4
5
  import { startServer } from "@tooltify/core";
@@ -16,17 +17,23 @@ function rspackTooltify({ publicUrl } = {}) {
16
17
  new compiler.rspack.DefinePlugin({
17
18
  __TOOLTIFY_PACKAGES_DIR__: JSON.stringify(config.packagesDir)
18
19
  }).apply(compiler);
20
+ const CLIENT_BUNDLE_PATH = path.resolve(__dirname, "../../../core/client/dist/client.iife.js");
19
21
  compiler.hooks.compilation.tap("tooltify", (compilation) => {
20
22
  compilation.hooks.processAssets.tap(
21
23
  { name: "tooltify", stage: compiler.rspack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE },
22
24
  (assets) => {
25
+ const clientCode = fs.readFileSync(CLIENT_BUNDLE_PATH);
26
+ compilation.emitAsset(
27
+ "tooltify.js",
28
+ new compiler.rspack.sources.RawSource(clientCode)
29
+ );
23
30
  for (const name of Object.keys(assets)) {
24
31
  if (name !== "index.html") continue;
25
32
  const html = assets[name].source().toString();
26
33
  const injected = html.replace(
27
34
  "</head>",
28
- `<script>window.__TOOLTIFY_URL__="${TOOLTIFY_URL}"</script>
29
- <script src="${TOOLTIFY_URL}/tooltify.js" defer></script>
35
+ `<script>window.__TOOLTIFY_URL__ = "${TOOLTIFY_URL}";</script>
36
+ <script src="/tooltify.js"></script>
30
37
  </head>`
31
38
  );
32
39
  compilation.updateAsset(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tooltify/integration-rspack",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",