Skip to content

Commit 862e192

Browse files
authored
refactor: use foo.endsWith("bar") instead of /bar$/.test(foo) (vitejs#20413)
1 parent 6bc8bf6 commit 862e192

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

packages/plugin-legacy/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
721721
if (isLegacyBundle(bundle, opts) && genModern) {
722722
// avoid emitting duplicate assets
723723
for (const name in bundle) {
724-
if (bundle[name].type === 'asset' && !/.+\.map$/.test(name)) {
724+
if (bundle[name].type === 'asset' && !name.endsWith('.map')) {
725725
delete bundle[name]
726726
}
727727
}

packages/vite/src/node/plugins/asset.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const jsSourceMapRE = /\.[cm]?js\.map$/
4242

4343
export const noInlineRE = /[?&]no-inline\b/
4444
export const inlineRE = /[?&]inline\b/
45-
const svgExtRE = /\.svg(?:$|\?)/
4645

4746
const assetCache = new WeakMap<Environment, Map<string, string>>()
4847

@@ -308,7 +307,7 @@ export async function fileToDevUrl(
308307
// If is svg and it's inlined in build, also inline it in dev to match
309308
// the behaviour in build due to quote handling differences.
310309
const cleanedId = cleanUrl(id)
311-
if (svgExtRE.test(cleanedId)) {
310+
if (cleanedId.endsWith('.svg')) {
312311
const file = publicFile || cleanedId
313312
const content = await fsp.readFile(file)
314313
if (shouldInline(environment, file, id, content, undefined, undefined)) {

0 commit comments

Comments
 (0)