davidmyersdev / vite-plugin-node-polyfills

A Vite plugin to polyfill Node's Core Modules for browser environments.
MIT License
263 stars 17 forks source link

Request: Add `include` option to only include pollyfills for certain packages #24

Closed oemer-aran closed 10 months ago

oemer-aran commented 1 year ago

Sometimes it's more beneficial to have an include option instead of an exclude one. In my case, I have a package that is importing only url and I only need to polyfill that.

Proposed API:

import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'

export default defineConfig({
  plugins: [
    nodePolyfills({
     // Only polyfill url module
      include: [
        'url'
      ],
      // Has no effect, when include is also provided
      exclude: [
        'fs', 
      ],

    }),
  ],
})
davidmyersdev commented 1 year ago

Agreed. That would be a great addition.

secondl1ght commented 11 months ago

This would be great, I only currently need to use the crypto module and I would like to keep my app size as small as possible. If adding include is not an option could we at least add a list of all the possible modules to the README so you know which ones to exclude? Also thanks a lot @davidmyersdev for this package it is very useful!

leticiavna commented 10 months ago

hi @davidmyersdev, thanks for this package! is this issue accepting contributions?

updated: i had the changes ready and I wanted to submit the PR before it gets stale =)