Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
vite-plugin-commonjs-externals
Advanced tools
Provides commonjs externals support for Vite.
Prevent bundling of certain esm import
ed packages and instead retrieve these external dependencies at runtime by commonjs require
.
For example:
import commonjsExternals from 'vite-plugin-commonjs-externals';
const externals = ['path', /^electron(\/.+)?$/];
export default {
optimizeDeps: {
exclude: externals,
},
plugins: commonjsExternals({
externals,
}),
};
This will convert it
import fs from 'fs';
import * as path from 'path';
import e1 from 'electron';
import e2, * as e3 from 'electron/main';
console.log({ fs, path, e1, e2, e3 });
to
import * as fs from 'fs';
const path = (() => {
const mod = require('path');
return mod?.__esModule
? mod
: Object.assign(Object.create(null), mod, {
default: mod,
[Symbol.toStringTag]: 'Module',
});
})();
const { default: e1 } = (() => {
const mod = require('electron');
return mod?.__esModule
? mod
: Object.assign(Object.create(null), mod, {
default: mod,
[Symbol.toStringTag]: 'Module',
});
})();
const e3 = (() => {
const mod = require('electron/main');
return mod?.__esModule
? mod
: Object.assign(Object.create(null), mod, {
default: mod,
[Symbol.toStringTag]: 'Module',
});
})();
const { default: e2 } = e3;
console.log({ fs, path, e1, e2, e3 });
// vite.config.ts
import { defineConfig } from 'vite';
import { escapeRegExp } from 'lodash';
import reactRefresh from '@vitejs/plugin-react-refresh';
import builtinModules from 'builtin-modules';
// For two package.json structure
import pkg from '../the-path-to-main-process-dir/package.json';
// For single package.json structure
import pkg from './package.json';
import commonjsExternals from 'vite-plugin-commonjs-externals';
const commonjsPackages = [
'electron',
'electron/main',
'electron/common',
'electron/renderer',
'original-fs',
...builtinModules,
...Object.keys(pkg.dependencies).map(
name => new RegExp('^' + escapeRegExp(name) + '(\\/.+)?$')
),
] as const;
export default defineConfig({
optimizeDeps: {
exclude: commonjsPackages,
},
plugins: [reactRefresh(), commonjsExternals({ externals: commonjsPackages })],
});
FAQs
Provides commonjs externals support for Vite.
The npm package vite-plugin-commonjs-externals receives a total of 2,101 weekly downloads. As such, vite-plugin-commonjs-externals popularity was classified as popular.
We found that vite-plugin-commonjs-externals demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.