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

@yellowspot/vite-plugin-externals

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yellowspot/vite-plugin-externals

Use to external resources, like webpack externals

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

vite-plugin-externals

Use external resources, like webpack externals

NPM version NPM Downloads

Install

npm i @yellowspot/vite-plugin-externals -D

Usage

import externals from '@yellowspot/vite-plugin-externals'

export default {
  plugins: [
    externals({
      jquery: `jQuery`,
    }),
  ]
}

How it works

Let's use jQuery as an example

externals({
  jquery: `window.jQuery`,
})
  1. It creates node_modules/.@yellowspot_vite-plugin-externals/jquery.cjs containing the following code
module.exports = window.jQuery;
  1. It registers a jquery alias item adding it to resolve.alias
{
  resolve: {
    alias: [
      {
        find: 'jquery',
        replacement: '/User/work-directory/node_modules/.@yellowspot_vite-plugin-externals/jquery.cjs',
      },
    ],
  },
}

Motivation

While migrating a project from webpack to vite, we needed a way to mimic webpack's externals. We found vite-plugin-external which does an excellent job. I couldn't use it because on build it relies on rollup global option which only works if the output format is umd / iife (see docs here).

We also tried vite-plugin-resolve without good results.

That's why we decided to write our own plugin on top of vite-plugin-optimizer

Keywords

FAQs

Package last updated on 23 Nov 2023

Did you know?

Socket

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.

Install

Related posts

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