Skip to content

Commit

Permalink
dynamic imports come from getAdaptedUrl from path.import.dev or path.…
Browse files Browse the repository at this point in the history
…import.release
  • Loading branch information
Horacio Daniel Ros committed Aug 29, 2024
1 parent f7911bb commit 6c1b85e
Showing 5 changed files with 20 additions and 27 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -4,4 +4,6 @@ package-lock.json
dist
dist/*
lib
lib/*
lib/*
.vscode/*
.vscode/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- markdownlint-disable-next-line -->
<div align="center">
<img src="https://raw.githubusercontent.com/hdrdevs/cedro/main/public/cedro-logo.svg" alt="Cedro" width="170">
<h1>cedro</h1>

</div>
<h6>Javascript library to build user interfece based on widgets.</h6>

27 changes: 2 additions & 25 deletions src/core/application.builder.tsx
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import { Widget, WidgetAlignTypes } from "../ui";
import { createWidget } from "../ui/widget.builder";
import Application, { ApplicationProps } from "./application.core";
import { decode } from "./html.entities";
import { getAdaptedUrl } from "./path.import.dev";

function getApplicationProps(content: any): ApplicationProps {
let props: ApplicationProps = {
@@ -66,32 +67,8 @@ export function createApplication(content: any): Application {
if (ietmRoute.getAttribute("w-route-path") && ietmRoute.getAttribute("href")) {
newApp.router.on(decode(ietmRoute.getAttribute("href")), () => {
const url = decode(ietmRoute.getAttribute("href"));
const timestamp = new Date().getTime();
const isProduction = process.env.NODE_ENV === "production";

/*
//DEVELOPMENT
const pathDev = ".." + url + "?ts=" + timestamp;
const pathProduction = `../../assets${decode(
ietmRoute.getAttribute("href")
)}/index.js?ts=${timestamp}`;
//FIN DEVELOPMENT
*/
//PUBLISH

const pathDev = "../../../../src" + url + "?ts=" + timestamp;

const pathProduction = `/assets${decode(
ietmRoute.getAttribute("href")
)}index.js?ts=${timestamp}`;

//FIN PUBLISH

const path = isProduction ? pathProduction : pathDev;

const path = getAdaptedUrl(url);
import(/*@vite-ignore*/ path).then((module) => {
newApp.clearLoadedModule();
newApp.setLoadedModule(module.default);
7 changes: 7 additions & 0 deletions src/core/path.import.dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const getAdaptedUrl = (url: string) => {
const timestamp = new Date().getTime();
const isProduction = process.env.NODE_ENV === "production";
const pathDev = ".." + url + "?ts=" + timestamp;
const pathProduction = `../../assets${url}/index.js?ts=${timestamp}`;
return isProduction ? pathProduction : pathDev;
};
7 changes: 7 additions & 0 deletions src/core/path.import.release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const getAdaptedUrl = (url: string) => {
const timestamp = new Date().getTime();
const isProduction = process.env.NODE_ENV === "production";
const pathDev = "../../../../src" + url + "?ts=" + timestamp;
const pathProduction = `/assets${url}index.js?ts=${timestamp}`;
return isProduction ? pathProduction : pathDev;
};

0 comments on commit 6c1b85e

Please sign in to comment.