Skip to content

Commit

Permalink
Merge pull request #65 from liamdon/featureOptions
Browse files Browse the repository at this point in the history
Provide options to disable devtools and prefresh
  • Loading branch information
marvinhagemeister committed Nov 15, 2022
2 parents e30e1c0 + e856824 commit a6dfd74
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export default defineConfig({

| Option | Type | Default | Description |
|---|---|---|---|
| `devToolsEnabled` | `boolean` | `true` | Inject devtools bridge |
| `prefreshEnabled` | `boolean` | `true` | Inject [Prefresh](https://github.com/preactjs/prefresh) for HMR |
| `devtoolsInProd` | `boolean` | `false` | Inject devtools bridge in production bundle instead of only in development mode |

### Babel configuration
Expand Down
29 changes: 27 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ export interface PreactPluginOptions {
* @default false
*/
devtoolsInProd?: boolean;

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

/**
* Whether to use prefresh HMR
* @default true
*/
prefreshEnabled?: boolean;

/**
* RegExp or glob to match files to be transformed
*/
Expand Down Expand Up @@ -52,6 +65,8 @@ 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,
include,
exclude,
babel,
Expand All @@ -75,6 +90,9 @@ function preactPlugin({
exclude || [/node_modules/],
);

devToolsEnabled = devToolsEnabled ?? true;
prefreshEnabled = prefreshEnabled ?? true;

const jsxPlugin: Plugin = {
name: "vite:preact-jsx",
enforce: "pre",
Expand Down Expand Up @@ -164,8 +182,15 @@ function preactPlugin({
},
},
jsxPlugin,
preactDevtoolsPlugin({ injectInProd: devtoolsInProd, shouldTransform }),
prefresh({ include, exclude }),
...(devToolsEnabled
? [
preactDevtoolsPlugin({
injectInProd: devtoolsInProd,
shouldTransform,
}),
]
: []),
...(prefreshEnabled ? [prefresh({ include, exclude })] : []),
];
}

Expand Down

0 comments on commit a6dfd74

Please sign in to comment.