Skip to content

Commit

Permalink
refactor: Remove devtoolsInProd option, default to dev/prod
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Mar 16, 2024
1 parent 08d0d8f commit 6542c68
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export default defineConfig({

| Option | Type | Default | Description |
|---|---|---|---|
| `devtoolsInProd` | `boolean` | `false` | Inject devtools bridge in production bundle instead of only in development mode |
| `devToolsEnabled` | `boolean` | `true` | Inject devtools bridge |
| `devToolsEnabled` | `boolean` | `!isProduction` | Inject devtools bridge |
| `prefreshEnabled` | `boolean` | `true` | Inject [Prefresh](https://github.com/preactjs/prefresh) for HMR |
| `reactAliasesEnabled` | `boolean` | `true` | Aliases `react`, `react-dom` to `preact/compat` |
| `babel` | `object` | | See [Babel configuration](#babel-configuration) |
Expand Down
5 changes: 1 addition & 4 deletions src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import type { RollupFilter } from "./utils.js";
import { parseId } from "./utils.js";

export interface PreactDevtoolsPluginOptions {
devtoolsInProd?: boolean;
devToolsEnabled?: boolean;
shouldTransform: RollupFilter;
}

export function preactDevtoolsPlugin({
devtoolsInProd,
devToolsEnabled,
shouldTransform,
}: PreactDevtoolsPluginOptions): Plugin {
Expand All @@ -39,8 +37,7 @@ export function preactDevtoolsPlugin({

configResolved(resolvedConfig) {
config = resolvedConfig;
devToolsEnabled =
devToolsEnabled ?? (!config.isProduction || devtoolsInProd);
devToolsEnabled = devToolsEnabled ?? !config.isProduction;
},

resolveId(url, importer = "") {
Expand Down
16 changes: 3 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ export type BabelOptions = Omit<
>;

export interface PreactPluginOptions {
/**
* Inject devtools bridge in production bundle instead of only in development mode.
* @default false
*/
devtoolsInProd?: boolean;

/**
* Whether to use Preact devtools
* @default true
* @default !isProduction
*/
devToolsEnabled?: boolean;

Expand Down Expand Up @@ -97,7 +91,6 @@ export interface PreactBabelOptions extends BabelOptions {

// Taken from https://github.com/vitejs/vite/blob/main/packages/plugin-react/src/index.ts
function preactPlugin({
devtoolsInProd,
devToolsEnabled,
prefreshEnabled,
reactAliasesEnabled,
Expand Down Expand Up @@ -131,7 +124,6 @@ function preactPlugin({
exclude || [/node_modules/],
);

devtoolsInProd = devtoolsInProd ?? false;
prefreshEnabled = prefreshEnabled ?? true;
reactAliasesEnabled = reactAliasesEnabled ?? true;
prerender = prerender ?? { enabled: false };
Expand All @@ -158,8 +150,7 @@ function preactPlugin({
},
configResolved(resolvedConfig) {
config = resolvedConfig;
devToolsEnabled =
devToolsEnabled ?? (!config.isProduction || devtoolsInProd);
devToolsEnabled = devToolsEnabled ?? !config.isProduction;
},
async transform(code, url) {
// Ignore query parameters, as in Vue SFC virtual modules.
Expand Down Expand Up @@ -238,9 +229,8 @@ function preactPlugin({
: []),
jsxPlugin,
preactDevtoolsPlugin({
devtoolsInProd,
devToolsEnabled,
shouldTransform,
shouldTransform
}),
...(prefreshEnabled
? [prefresh({ include, exclude, parserPlugins: baseParserOptions })]
Expand Down

0 comments on commit 6542c68

Please sign in to comment.