@tooltify/integration-rspack 0.1.2 → 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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import { RspackPluginInstance } from '@rspack/core';
2
2
 
3
- declare function rspackTooltify(): RspackPluginInstance;
3
+ interface StartOptions {
4
+ publicUrl?: string;
5
+ }
6
+
7
+ declare function rspackTooltify({ publicUrl }?: StartOptions): RspackPluginInstance;
4
8
 
5
9
  export { rspackTooltify };
package/dist/index.js CHANGED
@@ -1,13 +1,15 @@
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";
5
6
  var __dirname = path.dirname(fileURLToPath(import.meta.url));
6
7
  var CUSTOM_JSX_RUNTIME = path.resolve(__dirname, "./helpers/react-transform-source");
7
- function rspackTooltify() {
8
+ function rspackTooltify({ publicUrl } = {}) {
8
9
  return {
9
10
  apply(compiler) {
10
11
  const { config, port, buildTracker, cleanDeps } = startServer();
12
+ const TOOLTIFY_URL = publicUrl ? publicUrl : `http://localhost:${port}`;
11
13
  new compiler.rspack.NormalModuleReplacementPlugin(
12
14
  /^react\/jsx-dev-runtime$/,
13
15
  CUSTOM_JSX_RUNTIME
@@ -15,17 +17,23 @@ function rspackTooltify() {
15
17
  new compiler.rspack.DefinePlugin({
16
18
  __TOOLTIFY_PACKAGES_DIR__: JSON.stringify(config.packagesDir)
17
19
  }).apply(compiler);
20
+ const CLIENT_BUNDLE_PATH = path.resolve(__dirname, "../../../core/client/dist/client.iife.js");
18
21
  compiler.hooks.compilation.tap("tooltify", (compilation) => {
19
22
  compilation.hooks.processAssets.tap(
20
23
  { name: "tooltify", stage: compiler.rspack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE },
21
24
  (assets) => {
25
+ const clientCode = fs.readFileSync(CLIENT_BUNDLE_PATH);
26
+ compilation.emitAsset(
27
+ "tooltify.js",
28
+ new compiler.rspack.sources.RawSource(clientCode)
29
+ );
22
30
  for (const name of Object.keys(assets)) {
23
31
  if (name !== "index.html") continue;
24
32
  const html = assets[name].source().toString();
25
33
  const injected = html.replace(
26
34
  "</head>",
27
- `<script>window.__TOOLTIFY_URL__="http://localhost:${port}"</script>
28
- <script src="http://localhost:${port}/tooltify.js" defer></script>
35
+ `<script>window.__TOOLTIFY_URL__ = "${TOOLTIFY_URL}";</script>
36
+ <script src="/tooltify.js"></script>
29
37
  </head>`
30
38
  );
31
39
  compilation.updateAsset(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tooltify/integration-rspack",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "peerDependencies": {
21
21
  "@rspack/core": "^1.7.8",
22
- "@tooltify/core": "^0.1.2"
22
+ "@tooltify/core": "^0.1.3"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@tooltify/core": "*"