@preact/preset-vite
Advanced tools
Comparing version 1.0.0 to 1.0.1
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -8,26 +27,37 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var path_1 = __importDefault(require("path")); | ||
var debug_1 = __importDefault(require("debug")); | ||
var kl = __importStar(require("kolorist")); | ||
function preactDevtoolsPlugin(_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.injectInProd, injectInProd = _c === void 0 ? false : _c; | ||
var log = debug_1["default"]("vite:preact-devtools"); | ||
var entry = ""; | ||
var config; | ||
var found = false; | ||
var plugin = { | ||
name: "preact:devtools", | ||
// Ensure that we resolve before everything else | ||
enforce: "pre", | ||
configResolved: function (resolvedConfig) { | ||
config = resolvedConfig; | ||
}, | ||
transformIndexHtml: function (html) { | ||
// Use this to grab the initial entry js file to | ||
// inject "preact/debug" into at a later stage. | ||
var match = html.match(/<script type=["]module["] src=["](.*?)["]/); | ||
if (!match || !match.length) { | ||
throw new Error("Didn't find entry script tag in index.html"); | ||
resolveId: function (id, importer) { | ||
if (importer === void 0) { importer = ""; } | ||
// Get the main entry file to inject into | ||
if (!found && | ||
/\.html$/.test(importer) && | ||
!/\/node_modules\//.test(id) && | ||
/\.[tj]sx?$/.test(id)) { | ||
found = true; | ||
entry = path_1["default"].join(config.root, id); | ||
// TODO: Vite types require explicit return | ||
// undefined here. They're lacking the "void" type | ||
// in their declarations | ||
return undefined; | ||
} | ||
entry = path_1["default"].join(config.root, match[1]); | ||
return html; | ||
}, | ||
transform: function (code, id) { | ||
// Inject "preact/debug" or "preact/devtools" respectively | ||
if ((entry === id && config.command === "serve") || injectInProd) { | ||
if (entry === id && (config.command === "serve" || injectInProd)) { | ||
var source = injectInProd ? "preact/devtools" : "preact/debug"; | ||
code = "import \"" + source + "\";\n" + code; | ||
log("[inject] " + kl.cyan(source) + " -> " + kl.dim(id)); | ||
} | ||
@@ -34,0 +64,0 @@ return code; |
import path from "path"; | ||
import debug from "debug"; | ||
import * as kl from "kolorist"; | ||
export function preactDevtoolsPlugin(_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.injectInProd, injectInProd = _c === void 0 ? false : _c; | ||
var log = debug("vite:preact-devtools"); | ||
var entry = ""; | ||
var config; | ||
var found = false; | ||
var plugin = { | ||
name: "preact:devtools", | ||
// Ensure that we resolve before everything else | ||
enforce: "pre", | ||
configResolved: function (resolvedConfig) { | ||
config = resolvedConfig; | ||
}, | ||
transformIndexHtml: function (html) { | ||
// Use this to grab the initial entry js file to | ||
// inject "preact/debug" into at a later stage. | ||
var match = html.match(/<script type=["]module["] src=["](.*?)["]/); | ||
if (!match || !match.length) { | ||
throw new Error("Didn't find entry script tag in index.html"); | ||
resolveId: function (id, importer) { | ||
if (importer === void 0) { importer = ""; } | ||
// Get the main entry file to inject into | ||
if (!found && | ||
/\.html$/.test(importer) && | ||
!/\/node_modules\//.test(id) && | ||
/\.[tj]sx?$/.test(id)) { | ||
found = true; | ||
entry = path.join(config.root, id); | ||
// TODO: Vite types require explicit return | ||
// undefined here. They're lacking the "void" type | ||
// in their declarations | ||
return undefined; | ||
} | ||
entry = path.join(config.root, match[1]); | ||
return html; | ||
}, | ||
transform: function (code, id) { | ||
// Inject "preact/debug" or "preact/devtools" respectively | ||
if ((entry === id && config.command === "serve") || injectInProd) { | ||
if (entry === id && (config.command === "serve" || injectInProd)) { | ||
var source = injectInProd ? "preact/devtools" : "preact/debug"; | ||
code = "import \"" + source + "\";\n" + code; | ||
log("[inject] " + kl.cyan(source) + " -> " + kl.dim(id)); | ||
} | ||
@@ -27,0 +38,0 @@ return code; |
{ | ||
"name": "@preact/preset-vite", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Preact preset for the vite bundler", | ||
@@ -26,3 +26,5 @@ "main": "dist/cjs/index.js", | ||
"dependencies": { | ||
"@prefresh/vite": "^2.1.0" | ||
"@prefresh/vite": "^2.1.0", | ||
"debug": "^4.3.1", | ||
"kolorist": "^1.2.10" | ||
}, | ||
@@ -33,2 +35,3 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@types/debug": "^4.1.5", | ||
"@types/node": "^14.14.33", | ||
@@ -35,0 +38,0 @@ "lint-staged": "^10.5.4", |
@@ -8,3 +8,3 @@ # @preact/preset-vite | ||
- Sets up Hot Module Replacement via [prefresh](https://github.com/JoviDeCroock/prefresh/tree/main/packages/vite) | ||
- Enables [Preact Devtools](https://preactjs.github.io/preact-devtools/) bridge during development | ||
- Enables [Preact Devtools](https://preactjs.github.io/preact-devtools/) bridge during development | ||
@@ -21,7 +21,6 @@ ## Installation | ||
Enhance your vite config with the Preact preset: | ||
Enhance your vite config with the Preact preset: | ||
```js | ||
// vite.config.js or vite.config.ts | ||
import { defineConfig } from "vite"; | ||
import withPreact from "@preact/preset-vite"; | ||
@@ -39,3 +38,3 @@ | ||
```js | ||
withPreact(viteConfig, { | ||
export default withPreact(viteConfig, { | ||
// Add your options here | ||
@@ -50,3 +49,3 @@ devtoolsInProd: true | ||
|---|---|---|---| | ||
| `devtoolsInProd` | `boolean` | `false` | Inject devtools bridge in production bundle instead of only in development mode | | ||
| `devtoolsInProd` | `boolean` | `false` | Inject devtools bridge in production bundle instead of only in development mode | | ||
@@ -53,0 +52,0 @@ ## License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10109
176
4
9
51
+ Addeddebug@^4.3.1
+ Addedkolorist@^1.2.10
+ Addedkolorist@1.8.0(transitive)