fix: inject browser options into node-resolve plugin if config.browser is true

This commit is contained in:
Derrick Hammer 2023-07-02 03:59:42 -04:00
parent 76a0bca0d5
commit 70a531e5aa
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 25 additions and 1 deletions

View File

@ -75,7 +75,31 @@ export default function (): PresetAsset {
noSymlinks: ['rollup.config.ts'], noSymlinks: ['rollup.config.ts'],
supplementaryConfig: { supplementaryConfig: {
'gitignore': ['/rollup.config.ts'], 'gitignore': ['/rollup.config.ts'],
'rollup': resolve(CONFIGS, 'rollup.yaml'), 'rollup': (context) => {
const content = loadFile(resolve(CONFIGS, 'rollup.yaml')) as any;
if (context.custom.config.browser) {
let plugins = content.plugins.map((item) =>
Array.isArray(item) ? item[0] : item,
);
let resolvePluginName = plugins.filter((item) =>
item.includes('node-resolve'),
);
if (resolvePluginName.length) {
const index = plugins.indexOf(resolvePluginName[0]);
if (!Array.isArray(content.plugins[index])) {
content.plugins[index] = [content.plugins[index], {}];
}
content.plugins[index][1] = {
browser: true,
preferBuiltins: false,
};
}
}
return content;
},
'tsconfig': { 'tsconfig': {
compilerOptions: { compilerOptions: {
moduleResolution: 'nodenext', moduleResolution: 'nodenext',