-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
106 additions
and
14 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
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
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,62 @@ | ||
import path from "node:path"; | ||
|
||
import vitePlugin from "./vite.mjs"; | ||
|
||
|
||
// ******************************** | ||
|
||
export default QRDS; | ||
|
||
|
||
// ******************************** | ||
|
||
function QRDS() { | ||
var command = null; | ||
var vite = vitePlugin(); | ||
|
||
QRDS.vite = () => { | ||
// copy a subset of the vite plugin hooks that are still | ||
// necessary, even though astro plugin is mostly taking | ||
// over the task | ||
return { | ||
name: vite.name, | ||
enforce: vite.enforce, | ||
resolveId: vite.resolveId, | ||
load: vite.load, | ||
}; | ||
}; | ||
|
||
return { | ||
name: "astro-plugin-qrds", | ||
hooks: { | ||
["astro:config:setup"](options) { | ||
command = options.command; | ||
options.injectScript( | ||
"head-inline", | ||
`{let el=document.createElement("script");el.async=false;el.src="/qrds-external-bundle.js";document.head.appendChild(el);}` | ||
); | ||
}, | ||
["astro:config:done"](options) { | ||
// call the underlying vite plugin's `configResolved()` hook, | ||
// passing along to it (an artificial subset of) its expected | ||
// `config` object | ||
vite.configResolved({ | ||
command: ( | ||
command == "dev" ? "serve" : | ||
|
||
[ "preview", "build", ].includes(command) ? "build" : | ||
|
||
// note: should not use this! | ||
"unknown" | ||
), | ||
root: options.config.root.pathname, | ||
publicDir: options.config.publicDir.pathname, | ||
build: { | ||
// note: vite expects this to be relative to root | ||
outDir: options.config.outDir.pathname.replace(options.config.root.pathname,""), | ||
}, | ||
}); | ||
}, | ||
}, | ||
}; | ||
} |
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
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
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