Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-electron-renderer

Package Overview
Dependencies
Maintainers
2
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-electron-renderer - npm Package Compare versions

Comparing version 0.9.0 to 0.9.3

2

package.json
{
"name": "vite-plugin-electron-renderer",
"version": "0.9.0",
"version": "0.9.3",
"description": "Support use Node.js API in Electron-Renderer",

@@ -5,0 +5,0 @@ "main": "plugins/index.js",

@@ -8,7 +8,7 @@ "use strict";

config(config) {
var _a, _b, _c, _d, _e;
var _f, _g, _h;
// make sure that Electron can be loaded into the local file using `loadFile` after packaging
if (config.base === undefined)
config.base = './';
if (config.build === undefined)
config.build = {};
(_a = config.base) !== null && _a !== void 0 ? _a : (config.base = './');
(_b = config.build) !== null && _b !== void 0 ? _b : (config.build = {});
// TODO: init `config.build.target`

@@ -18,10 +18,7 @@ // https://github.com/vitejs/vite/pull/8843

// TODO: Automatic splicing `build.assetsDir`
if (config.build.assetsDir === undefined)
config.build.assetsDir = '';
(_c = (_f = config.build).assetsDir) !== null && _c !== void 0 ? _c : (_f.assetsDir = '');
// https://github.com/electron-vite/electron-vite-vue/issues/107
if (config.build.cssCodeSplit === undefined)
config.build.cssCodeSplit = false;
(_d = (_g = config.build).cssCodeSplit) !== null && _d !== void 0 ? _d : (_g.cssCodeSplit = false);
// prevent accidental clearing of `dist/electron/main`, `dist/electron/preload`
if (config.build.emptyOutDir === undefined)
config.build.emptyOutDir = false;
(_e = (_h = config.build).emptyOutDir) !== null && _e !== void 0 ? _e : (_h.emptyOutDir = false);
},

@@ -28,0 +25,0 @@ };

@@ -13,5 +13,5 @@ "use strict";

(0, polyfill_exports_1.default)(),
(0, use_node_js_1.default)(options),
...(0, use_node_js_1.default)(options),
];
}
exports.default = renderer;

@@ -9,3 +9,3 @@ import { type Plugin } from 'vite';

}
export default function useNodeJs(options?: UseNodeJsOptions): Plugin;
export default function useNodeJs(options?: UseNodeJsOptions): Plugin[];
export declare function resolveModules(root: string, options?: UseNodeJsOptions): {

@@ -12,0 +12,0 @@ builtins: string[];

@@ -83,27 +83,53 @@ "use strict";

const electron = require("electron");
const {
clipboard,
nativeImage,
shell,
contextBridge,
crashReporter,
ipcRenderer,
webFrame,
desktopCapturer,
deprecate,
} = electron;
export {
electron as default,
clipboard,
nativeImage,
shell,
contextBridge,
crashReporter,
ipcRenderer,
webFrame,
desktopCapturer,
deprecate,
// Proxy in Worker
let _ipcRenderer;
if (typeof document === 'undefined') {
_ipcRenderer = {};
const keys = [
'invoke',
'postMessage',
'send',
'sendSync',
'sendTo',
'sendToHost',
// propertype
'addListener',
'emit',
'eventNames',
'getMaxListeners',
'listenerCount',
'listeners',
'off',
'on',
'once',
'prependListener',
'prependOnceListener',
'rawListeners',
'removeAllListeners',
'removeListener',
'setMaxListeners',
];
for (const key of keys) {
_ipcRenderer[key] = () => {
throw new Error(
'ipcRenderer doesn\\'t work in a Web Worker.\\n' +
'You can see https://github.com/electron-vite/vite-plugin-electron/issues/69'
);
};
}
} else {
_ipcRenderer = electron.ipcRenderer;
}
`.trim();
export { electron as default };
export const clipboard = electron.clipboard;
export const contextBridge = electron.contextBridge;
export const crashReporter = electron.crashReporter;
export const ipcRenderer = _ipcRenderer;
export const nativeImage = electron.nativeImage;
export const shell = electron.shell;
export const webFrame = electron.webFrame;
export const deprecate = electron.deprecate;
`;
function useNodeJs(options = {}) {

@@ -119,6 +145,17 @@ let env;

const prefix = '\0';
return {
name: 'vite-plugin-electron-renderer:use-node.js',
const pluginResolveId = {
name: 'vite-plugin-electron-renderer:use-node.js[resolveId]',
// Bypassing Vite's builtin 'vite:resolve' plugin
enforce: 'pre',
resolveId(source) {
if (env.command === 'serve') {
if (ESM_deps.includes(source))
return; // by vite-plugin-esmodule
if (CJS_modules.includes(source))
return prefix + source;
}
},
};
const plugin = {
name: 'vite-plugin-electron-renderer:use-node.js',
// 🚧 Must be use config hook

@@ -203,10 +240,2 @@ config(config, _env) {

},
resolveId(source) {
if (env.command === 'serve') {
if (ESM_deps.includes(source))
return; // by vite-plugin-esmodule
if (CJS_modules.includes(source))
return prefix + source;
}
},
load(id) {

@@ -256,6 +285,6 @@ if (env.command === 'serve') {

const nodeModuleCodeSnippet = `
${requireModule}
${exportDefault}
${exportMembers}
`.trim();
${requireModule}
${exportDefault}
${exportMembers}
`;
moduleCache.set(id, nodeModuleCodeSnippet);

@@ -267,2 +296,6 @@ return nodeModuleCodeSnippet;

};
return [
pluginResolveId,
plugin,
];
}

@@ -269,0 +302,0 @@ exports.default = useNodeJs;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc