✨ feat: implement mock data support with API interceptor and update documentation
This commit is contained in:
@@ -44,6 +44,25 @@ const resolvePlugin = {
|
||||
},
|
||||
}
|
||||
|
||||
// When MOCK is disabled, replace the mock module with a no-op stub so
|
||||
// esbuild can tree-shake all mock data out of the production bundle.
|
||||
const mockPlugin = {
|
||||
name: "mockPlugin",
|
||||
setup(build) {
|
||||
if (process.env.MOCK !== "1") {
|
||||
build.onResolve({ filter: /\/mock$/ }, (args) => {
|
||||
if (args.importer.includes("api.ts") || args.importer.includes("api.js")) {
|
||||
return { path: "mock-noop", namespace: "mock-noop" }
|
||||
}
|
||||
})
|
||||
build.onLoad({ filter: /.*/, namespace: "mock-noop" }, () => ({
|
||||
contents: "export function mockApiRequest() { return null }",
|
||||
loader: "ts",
|
||||
}))
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
////////////////////////// esbuild-svelte
|
||||
|
||||
const sveltePlugin = require("esbuild-svelte")
|
||||
@@ -84,7 +103,10 @@ const options = {
|
||||
minify: process.argv[2] == "build",
|
||||
bundle: true,
|
||||
splitting: false,
|
||||
plugins: [esbuildSvelte, postcssPlugin(), resolvePlugin],
|
||||
define: {
|
||||
__MOCK__: process.env.MOCK === "1" ? "true" : "false",
|
||||
},
|
||||
plugins: [esbuildSvelte, postcssPlugin(), resolvePlugin, mockPlugin],
|
||||
loader: {
|
||||
".woff2": "file",
|
||||
".woff": "file",
|
||||
|
||||
Reference in New Issue
Block a user