Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add customURL option to adastraTagSnippetDev to let it work with ngrok #42 #43

Open
robotshatemonkeys opened this issue Jun 11, 2024 · 0 comments

Comments

@robotshatemonkeys
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/adastra-plugin/dist/index.cjs b/node_modules/adastra-plugin/dist/index.cjs
index 3c1655e..03d5258 100644
--- a/node_modules/adastra-plugin/dist/index.cjs
+++ b/node_modules/adastra-plugin/dist/index.cjs
@@ -41,7 +41,8 @@ var resolveOptions = ({
   sourceDir = "src",
   entrypointsDir = "entrypoints",
   additionalEntrypoints = [],
-  snippetName = "adastra"
+  snippetName = "adastra",
+  ngrokUrl = "localhost:5173"
 }) => {
   const resolvedEntrypointsDir = import_path.default.join(sourceDir, entrypointsDir);
   return {
@@ -49,7 +50,8 @@ var resolveOptions = ({
     sourceDir,
     entrypointsDir: resolvedEntrypointsDir,
     additionalEntrypoints,
-    snippetName
+    snippetName,
+    ngrokUrl
   };
 };
 
@@ -191,12 +193,12 @@ var adastraEntryTag = (entryPaths, tag, isFirstEntry = false) => `{% ${!isFirstE
 var preloadScriptTag = (fileName) => `<link rel="modulepreload" href="{{ '${fileName}' | asset_url | split: '?' | first }}" as="script" crossorigin="anonymous">`;
 var scriptTag = (fileName) => `<script src="{{ '${fileName}' | asset_url | split: '?' | first }}" type="module" crossorigin="anonymous"></script>`;
 var stylesheetTag = (fileName) => `{{ '${fileName}' | asset_url | split: '?' | first | stylesheet_tag: preload: preload }}`;
-var adastraTagSnippetDev = (assetHost, entrypointsDir) => `{% liquid
+var adastraTagSnippetDev = (assetHost, entrypointsDir, ngrokUrl) => `{% liquid
   assign path_prefix = path | slice: 0
   if path_prefix == '/'
-    assign file_url_prefix = '${assetHost}'
+    assign file_url_prefix = '${(ngrokUrl) ? ngrokUrl : assetHost}'
   else
-    assign file_url_prefix = '${assetHost}/${entrypointsDir}/'
+    assign file_url_prefix = '${(ngrokUrl) ? ngrokUrl : assetHost}/${entrypointsDir}/'
   endif
 
   assign file_url = path | prepend: file_url_prefix
@@ -259,10 +261,10 @@ function resolveDevServerUrl(address, config) {
 }
 function isIpv6(address) {
   return address.family === "IPv6" || // In node >=18.0 <18.4 this was an integer value. This was changed in a minor version.
-  // See: https://github.com/laravel/vite-plugin/issues/103
-  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
-  // @ts-expect-error-next-line
-  address.family === 6;
+    // See: https://github.com/laravel/vite-plugin/issues/103
+    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+    // @ts-expect-error-next-line
+    address.family === 6;
 }
 
 // src/plugins/vite-plugin-adastra-liquid.ts
@@ -292,8 +294,10 @@ var vite_plugin_adastra_liquid_default = (options) => {
             config2.resolve.alias,
             options.entrypointsDir,
             adastraSnippetName
-          ) + adastraTagSnippetDev(devServerUrl, options.entrypointsDir);
+          ) + adastraTagSnippetDev(devServerUrl, options.entrypointsDir, options.ngrokUrl);
           import_fs.default.writeFileSync(adastraSnippetPath, adastraTagSnippetContent);
+
+          console.log("options", options)
         }
       });
       return () => middlewares.use((req, res, next) => {
diff --git a/node_modules/adastra-plugin/dist/index.js b/node_modules/adastra-plugin/dist/index.js
index 1b6476b..8ae4edc 100644
--- a/node_modules/adastra-plugin/dist/index.js
+++ b/node_modules/adastra-plugin/dist/index.js
@@ -208,6 +208,7 @@ var adastraTagSnippetDev = (assetHost, entrypointsDir) => `{% liquid
 
 // src/utilities/dev-server.ts
 function resolveDevServerUrl(address, config) {
+  console.log('resolveDevServerUrl', config);
   const configHmr = config.server.hmr;
   const configHmrProtocol = typeof configHmr === "object" ? configHmr.protocol : null;
   const configHmrHost = typeof configHmr === "object" ? configHmr.host : null;
@@ -223,10 +224,10 @@ function resolveDevServerUrl(address, config) {
 }
 function isIpv6(address) {
   return address.family === "IPv6" || // In node >=18.0 <18.4 this was an integer value. This was changed in a minor version.
-  // See: https://github.com/laravel/vite-plugin/issues/103
-  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
-  // @ts-expect-error-next-line
-  address.family === 6;
+    // See: https://github.com/laravel/vite-plugin/issues/103
+    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+    // @ts-expect-error-next-line
+    address.family === 6;
 }
 
 // src/plugins/vite-plugin-adastra-liquid.ts

This issue body was partially generated by patch-package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant