-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51dddae
commit 3f48c9d
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Plugin } from 'vite'; | ||
|
||
// Fix for "Can't resolve original location of error" error when using source maps to build | ||
export const warningsToIgnore = [ | ||
['SOURCEMAP_ERROR', 'Can\'t resolve original location of error'], | ||
] | ||
/** | ||
* @see https://github.com/vitejs/vite/issues/15012#issuecomment-1825035992 | ||
* @param warningsToIgnore | ||
* @returns a Vite plugin that mutes warnings | ||
*/ | ||
const muteWarningsPlugin = (warningsToIgnore: string[][]): Plugin => { | ||
const mutedMessages = new Set() | ||
return { | ||
name: 'mute-warnings', | ||
enforce: 'pre', | ||
config: (userConfig) => ({ | ||
build: { | ||
rollupOptions: { | ||
onwarn(warning, defaultHandler) { | ||
if (warning.code) { | ||
const muted = warningsToIgnore.find( | ||
([code, message]) => | ||
code == warning.code && warning.message.includes(message), | ||
) | ||
|
||
if (muted) { | ||
mutedMessages.add(muted.join()) | ||
return | ||
} | ||
} | ||
|
||
if (userConfig.build?.rollupOptions?.onwarn) { | ||
userConfig.build.rollupOptions.onwarn(warning, defaultHandler) | ||
} else { | ||
defaultHandler(warning) | ||
} | ||
}, | ||
}, | ||
}, | ||
}), | ||
closeBundle() { | ||
const diff = warningsToIgnore.filter((x) => !mutedMessages.has(x.join())) | ||
if (diff.length > 0) { | ||
this.warn( | ||
'Some of your muted warnings never appeared during the build process:', | ||
) | ||
diff.forEach((m) => this.warn(`- ${m.join(': ')}`)) | ||
} | ||
}, | ||
} | ||
} | ||
|
||
export default muteWarningsPlugin; |