Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove devtoolsInProd option, default to dev/prod #112

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading