Skip to content

How can I inject lodash into an application like webpack's provideplugin #2091

Answered by jonaskuske
Vgbire asked this question in Q&A
Discussion options

You must be logged in to vote

Edit: doesn't work, as inject isn't available in the per-file transform API that Vite uses – however, using a small custom plugin to transform the code does work, see my reply down below: #2091 (reply in thread)

You should be able to use esbuild's inject option: https://esbuild.github.io/api/#inject

Something like this:

// vite.config.js
import path from 'path'
import { defineConfig, normalizePath } from 'vite'

export default defineConfig ({
  esbuild {
    inject: normalizePath(path.resolve(__dirname, 'lodash-shim.js'))
  }
}
// lodash-shim.js
export * as _ from 'lodash-es'

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
8 replies
@jonaskuske
Comment options

@Vgbire
Comment options

@Vgbire
Comment options

@Vgbire
Comment options

@jonaskuske
Comment options

Answer selected by Vgbire
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants