-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@marko/vite": patch | ||
--- | ||
|
||
Allow importing assets from marko file in cjs libs |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo |
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); | ||
} | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "isomorphic-commonjs-dir-import", | ||
"type": "commonjs", | ||
"dependencies": { | ||
"test-package": "0.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// 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"; | ||
import { handler } from "./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); | ||
}); |
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import template from "./template.marko"; | ||
|
||
export function handler(req, res) { | ||
if (req.url === "/") { | ||
res.statusCode = 200; | ||
res.setHeader("Content-Type", "text/html; charset=utf-8"); | ||
template.render({}, res); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// import addMonths from 'date-fns/addMonths'; | ||
|
||
import sub from "test-package/sub"; | ||
style { | ||
div { | ||
color: green; | ||
} | ||
} | ||
|
||
<layout-component> | ||
<div id="app"> | ||
${sub} | ||
</div> | ||
</layout-component> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ssr = true; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<button> | ||
<img | ||
alt="icon" | ||
src="/assets/icon-[hash].svg" | ||
/> | ||
</button> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<button> | ||
<img | ||
alt="icon" | ||
src="/node_modules/test-package/components/test-icon/icon.svg" | ||
/> | ||
</button> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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) { | ||
try { | ||
devServer.ssrFixStacktrace(err); | ||
} catch (_) {} | ||
return next(err); | ||
} | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "isomorphic-commonjs", | ||
"dependencies": { | ||
"test-package": "0.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// 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"; | ||
import { handler } from "./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); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class { | ||
onCreate() { | ||
this.state = { | ||
clickCount: 0, | ||
mounted: false | ||
}; | ||
} | ||
onMount() { | ||
this.state.mounted = true; | ||
} | ||
handleClick() { | ||
this.state.clickCount++; | ||
} | ||
} | ||
|
||
<test-button#clickable on-click("handleClick")> | ||
Mounted: ${state.mounted} | ||
Clicks: ${state.clickCount} | ||
</test-button> |
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> |
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import template from "./template.marko"; | ||
|
||
export function handler(req, res) { | ||
if (req.url === "/") { | ||
res.statusCode = 200; | ||
res.setHeader("Content-Type", "text/html; charset=utf-8"); | ||
template.render( | ||
{}, | ||
{ | ||
write(chunk) { | ||
res.write(chunk); | ||
}, | ||
end(chunk) { | ||
res.end(chunk); | ||
}, | ||
}, | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div id="app"> | ||
<test-button/> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const ssr = true; | ||
export async function steps() {} |