Skip to content

Commit 1490d48

Browse files
committed
feat: source map supper to replace plugin
1 parent 13f39c3 commit 1490d48

File tree

8 files changed

+1531
-152
lines changed

8 files changed

+1531
-152
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mountHTML(`
2+
<div>
3+
Hello world!
4+
</div>
5+
`);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function vitePluginReplace() {
2+
return {
3+
name: "replace-plugin",
4+
transform(src, id) {
5+
if (id.includes("tutorial-example.js")) {
6+
return { code: src };
7+
}
8+
},
9+
};
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { defineConfig } from "vite";
2+
import Inspect from "vite-plugin-inspect";
3+
import replacePlugin from "./vite-plugin-replace";
4+
5+
export default defineConfig({
6+
plugins: [
7+
Inspect({
8+
build: true,
9+
outputDir: ".vite-inspect",
10+
}),
11+
12+
replacePlugin({
13+
from: "Initial value",
14+
to: "Replaced value",
15+
}),
16+
],
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function vitePluginReplace(options) {
2+
return {
3+
name: "replace-plugin",
4+
transform(src, id) {
5+
if (id.includes("tutorial-example.js")) {
6+
return { code: src.replaceAll(options.from, options.to) };
7+
}
8+
},
9+
};
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from "vite";
2+
import replacePlugin from "./vite-plugin-replace";
3+
4+
export default defineConfig({
5+
plugins: [
6+
replacePlugin({
7+
from: "Hello world",
8+
to: "Replaced value",
9+
}),
10+
],
11+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
type: lesson
3+
title: Source map support
4+
focus: /vite.config.ts
5+
previews:
6+
- [5173, "Vite dev server"]
7+
- [3000, "Vite plugin inspect"]
8+
mainCommand: ["npm run inspect", "Inspect Vite build"]
9+
prepareCommands:
10+
- ["npm install", "Installing dependencies"]
11+
- ["npm run build", "Build project"]
12+
---
13+
14+
# Source map support

0 commit comments

Comments
 (0)