Repository navigation
[@rollup/plugin-replace] How to replace a string inside node_modules #1646
Replies: 1 comment
|
Yes,
For a dependency whose source contains exactly import replace from '@rollup/plugin-replace';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
{
...replace({
// Replace this placeholder with the installed legacy plugin's package name.
include: ['**/node_modules/YOUR-LEGACY-PACKAGE/**'],
preventAssignment: true,
delimiters: ['', ''],
values: {
'factory( jQuery );': 'factory( window.jQuery );',
},
}),
enforce: 'pre',
apply: 'build',
},
],
// Keep the rest of your existing build configuration.
});This puts the replacement before normal transforms. I checked a minimal dependency under Relevant docs: include/exclude and delimiters. |
Uh oh!
There was an error while loading. Please reload this page.
I have a following vite.config.mts config:
I'm using some of the legacy jquery plugins, that are installed as npm packages, and I need to replace this inside them:
With this:
Unfortunately my current config does not replace
factory( window.jQuery );withfactory( jQuery );. The first replace({...}) works fine however fine however:Is there any way to replace a string inside node_modules?
All reactions