Skip to content

Commit d283242

Browse files
committed
refactor: Remove devtoolsInProd option, default to dev/prod
1 parent 238a9f8 commit d283242

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ export default defineConfig({
4545

4646
| Option | Type | Default | Description |
4747
|---|---|---|---|
48-
| `devtoolsInProd` | `boolean` | `false` | Inject devtools bridge in production bundle instead of only in development mode |
49-
| `devToolsEnabled` | `boolean` | `true` | Inject devtools bridge |
48+
| `devToolsEnabled` | `boolean` | `!isProduction` | Inject devtools bridge |
5049
| `prefreshEnabled` | `boolean` | `true` | Inject [Prefresh](https://github.com/preactjs/prefresh) for HMR |
5150
| `reactAliasesEnabled` | `boolean` | `true` | Aliases `react`, `react-dom` to `preact/compat` |
5251
| `babel` | `object` | | See [Babel configuration](#babel-configuration) |

src/devtools.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import type { RollupFilter } from "./utils.js";
77
import { parseId } from "./utils.js";
88

99
export interface PreactDevtoolsPluginOptions {
10-
injectInProd?: boolean;
10+
devToolsEnabled?: boolean;
1111
shouldTransform: RollupFilter;
1212
}
1313

1414
export function preactDevtoolsPlugin({
15-
injectInProd = false,
15+
devToolsEnabled,
1616
shouldTransform,
1717
}: PreactDevtoolsPluginOptions): Plugin {
1818
const log = debug("vite:preact-devtools");
@@ -37,6 +37,7 @@ export function preactDevtoolsPlugin({
3737

3838
configResolved(resolvedConfig) {
3939
config = resolvedConfig;
40+
devToolsEnabled ??= !config.isProduction;
4041
},
4142

4243
resolveId(url, importer = "") {
@@ -58,8 +59,8 @@ export function preactDevtoolsPlugin({
5859
transform(code, url) {
5960
const { id } = parseId(url);
6061

61-
if (entry === id && (!config.isProduction || injectInProd)) {
62-
const source = injectInProd ? "preact/devtools" : "preact/debug";
62+
if (entry === id) {
63+
const source = devToolsEnabled ? "preact/devtools" : "preact/debug";
6364
code = `import "${source}";\n${code}`;
6465

6566
log(`[inject] ${kl.cyan(source)} -> ${kl.dim(id)}`);

src/index.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,9 @@ export type BabelOptions = Omit<
2020
>;
2121

2222
export interface PreactPluginOptions {
23-
/**
24-
* Inject devtools bridge in production bundle instead of only in development mode.
25-
* @default false
26-
*/
27-
devtoolsInProd?: boolean;
28-
2923
/**
3024
* Whether to use Preact devtools
31-
* @default true
25+
* @default !isProduction
3226
*/
3327
devToolsEnabled?: boolean;
3428

@@ -97,7 +91,6 @@ export interface PreactBabelOptions extends BabelOptions {
9791

9892
// Taken from https://github.com/vitejs/vite/blob/main/packages/plugin-react/src/index.ts
9993
function preactPlugin({
100-
devtoolsInProd,
10194
devToolsEnabled,
10295
prefreshEnabled,
10396
reactAliasesEnabled,
@@ -131,7 +124,6 @@ function preactPlugin({
131124
exclude || [/node_modules/],
132125
);
133126

134-
devToolsEnabled = devToolsEnabled ?? true;
135127
prefreshEnabled = prefreshEnabled ?? true;
136128
reactAliasesEnabled = reactAliasesEnabled ?? true;
137129
prerender = prerender ?? { enabled: false };
@@ -158,6 +150,7 @@ function preactPlugin({
158150
},
159151
configResolved(resolvedConfig) {
160152
config = resolvedConfig;
153+
devToolsEnabled ??= !config.isProduction;
161154
},
162155
async transform(code, url) {
163156
// Ignore query parameters, as in Vue SFC virtual modules.
@@ -200,7 +193,7 @@ function preactPlugin({
200193
importSource: jsxImportSource ?? "preact",
201194
},
202195
],
203-
...(devToolsEnabled && !config.isProduction ? ["babel-plugin-transform-hook-names"] : []),
196+
...(devToolsEnabled ? ["babel-plugin-transform-hook-names"] : []),
204197
],
205198
sourceMaps: true,
206199
inputSourceMap: false as any,
@@ -235,14 +228,7 @@ function preactPlugin({
235228
]
236229
: []),
237230
jsxPlugin,
238-
...(devToolsEnabled
239-
? [
240-
preactDevtoolsPlugin({
241-
injectInProd: devtoolsInProd,
242-
shouldTransform,
243-
}),
244-
]
245-
: []),
231+
preactDevtoolsPlugin({ shouldTransform }),
246232
...(prefreshEnabled
247233
? [prefresh({ include, exclude, parserPlugins: baseParserOptions })]
248234
: []),

0 commit comments

Comments
 (0)