-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: relative assets transform (#109)
- Loading branch information
1 parent
430a291
commit 257b5d0
Showing
23 changed files
with
385 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@marko/vite": minor | ||
--- | ||
|
||
Support inline relative asset paths from native tags. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...s__/fixtures/isomorphic-relative-asset-import/__snapshots__/build.expected.loading.0.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div | ||
id="implicit" | ||
> | ||
<div | ||
id="clickable" | ||
> | ||
Mounted: false Clicks: 0 | ||
<img | ||
alt="logo" | ||
src="/assets/logo-[hash].svg" | ||
/> | ||
</div> | ||
</div> |
13 changes: 13 additions & 0 deletions
13
...s__/fixtures/isomorphic-relative-asset-import/__snapshots__/build.expected.loading.1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div | ||
id="implicit" | ||
> | ||
<div | ||
id="clickable" | ||
> | ||
Mounted: true Clicks: 0 | ||
<img | ||
alt="logo" | ||
src="/assets/logo-[hash].svg" | ||
/> | ||
</div> | ||
</div> |
13 changes: 13 additions & 0 deletions
13
...ts__/fixtures/isomorphic-relative-asset-import/__snapshots__/build.expected.step-0.0.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div | ||
id="implicit" | ||
> | ||
<div | ||
id="clickable" | ||
> | ||
Mounted: true Clicks: 1 | ||
<img | ||
alt="logo" | ||
src="/assets/logo-[hash].svg" | ||
/> | ||
</div> | ||
</div> |
13 changes: 13 additions & 0 deletions
13
...sts__/fixtures/isomorphic-relative-asset-import/__snapshots__/dev.expected.loading.0.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div | ||
id="implicit" | ||
> | ||
<div | ||
id="clickable" | ||
> | ||
Mounted: false Clicks: 0 | ||
<img | ||
alt="logo" | ||
src="/src/components/logo.svg" | ||
/> | ||
</div> | ||
</div> |
13 changes: 13 additions & 0 deletions
13
...sts__/fixtures/isomorphic-relative-asset-import/__snapshots__/dev.expected.loading.1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div | ||
id="implicit" | ||
> | ||
<div | ||
id="clickable" | ||
> | ||
Mounted: true Clicks: 0 | ||
<img | ||
alt="logo" | ||
src="/src/components/logo.svg" | ||
/> | ||
</div> | ||
</div> |
13 changes: 13 additions & 0 deletions
13
...ests__/fixtures/isomorphic-relative-asset-import/__snapshots__/dev.expected.step-0.0.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div | ||
id="implicit" | ||
> | ||
<div | ||
id="clickable" | ||
> | ||
Mounted: true Clicks: 1 | ||
<img | ||
alt="logo" | ||
src="/src/components/logo.svg" | ||
/> | ||
</div> | ||
</div> |
38 changes: 38 additions & 0 deletions
38
src/__tests__/fixtures/isomorphic-relative-asset-import/dev-server.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// In dev we'll start a Vite dev server in middleware mode, | ||
// and forward requests to our http request handler. | ||
|
||
import { createServer } from "vite"; | ||
import path from "path"; | ||
import url from "url"; | ||
import { createRequire } from "module"; | ||
|
||
// change to import once marko-vite is updated to ESM | ||
const markoPlugin = createRequire(import.meta.url)("../../..").default; | ||
|
||
const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); | ||
|
||
const devServer = await createServer({ | ||
root: __dirname, | ||
appType: "custom", | ||
logLevel: "silent", | ||
plugins: [markoPlugin()], | ||
optimizeDeps: { force: true }, | ||
server: { | ||
middlewareMode: true, | ||
watch: { | ||
ignored: ["**/node_modules/**", "**/dist/**", "**/__snapshots__/**"], | ||
}, | ||
}, | ||
}); | ||
|
||
export default devServer.middlewares.use(async (req, res, next) => { | ||
try { | ||
const { handler } = await devServer.ssrLoadModule( | ||
path.join(__dirname, "./src/index.js") | ||
); | ||
await handler(req, res, next); | ||
} catch (err) { | ||
devServer.ssrFixStacktrace(err); | ||
return next(err); | ||
} | ||
}); |
18 changes: 18 additions & 0 deletions
18
src/__tests__/fixtures/isomorphic-relative-asset-import/server.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// In production, simply start up the http server. | ||
import path from 'path' | ||
import url from 'url'; | ||
import { createServer } from "http"; | ||
import serve from "serve-handler"; | ||
|
||
globalThis.assetsPath = "/my-prefix/"; | ||
// dyanmic import so globalThis.assetsPath can be set prior to the imported code executing | ||
const { handler } = await import("./dist/index.mjs"); | ||
|
||
const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); | ||
const serveOpts = { public: path.resolve(__dirname, "dist") }; | ||
|
||
export default createServer(async (req, res) => { | ||
await handler(req, res); | ||
if (res.headersSent) return; | ||
await serve(req, res, serveOpts); | ||
}); |
22 changes: 22 additions & 0 deletions
22
src/__tests__/fixtures/isomorphic-relative-asset-import/src/components/class-component.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class { | ||
onCreate() { | ||
this.state = { | ||
clickCount: 0, | ||
mounted: false | ||
}; | ||
} | ||
onMount() { | ||
this.state.mounted = true; | ||
} | ||
handleClick() { | ||
this.state.clickCount++; | ||
} | ||
} | ||
|
||
<div#clickable onClick("handleClick")> | ||
Mounted: ${state.mounted} | ||
Clicks: ${state.clickCount} | ||
|
||
<img src="./logo.svg" alt="logo"> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
...tests__/fixtures/isomorphic-relative-asset-import/src/components/implicit-component.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
static { | ||
if (typeof window === "object") { | ||
document.body.firstElementChild.append("Loaded Implicit Component"); | ||
} | ||
} | ||
|
||
<div#implicit> | ||
<class-component/> | ||
</div> |
15 changes: 15 additions & 0 deletions
15
...__tests__/fixtures/isomorphic-relative-asset-import/src/components/layout-component.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
static { | ||
if (typeof window === "object") { | ||
document.body.firstElementChild.append("Loaded Layout Component"); | ||
} | ||
} | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Hello World</title> | ||
</head> | ||
<body> | ||
<${input.renderBody}/> | ||
</body> | ||
</html> |
Oops, something went wrong.