JorgenVatle / meteor-vite

⚡ Replace Meteor's bundler with Vite for blazing fast build-times
MIT License
16 stars 5 forks source link

Add option to externalize import requests for npm packages already provided by Meteor. #118

Closed JorgenVatle closed 2 months ago

JorgenVatle commented 3 months ago

This addresses an issue where Meteor packages that come bundled with npm packages might be included twice if your client app also depends on the same npm package.

Instructing Vite to import from Meteor instead of node_modules

Per-import

// No changes here. 
// This will import from your node_modules like you would expect
import MyPackage from 'some-npm-package'

// If you have a Meteor package that already comes bundled with an npm package, the following
// syntax can be used to tell Vite to externalize this import request.
import MyPackage from 'meteor:some-npm-package';

Both imports are safe to use together. Bearing in mind that both versions of the npm package will be included in your final client bundle.

For all imports

// vite.config.ts
export default defineConfig({
  plugins: [
    meteor({
      externalizeNpmPackages: ['some-npm-package']
    })
  ]
})

Todo