Skip to content

Commit

Permalink
chore: use injectQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
sun0day committed Apr 30, 2023
1 parent bcf7899 commit 354c779
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/vite/src/node/plugins/assetImportMetaUrl.ts
@@ -1,11 +1,11 @@
import path from 'node:path'
import MagicString from 'magic-string'
import { stripLiteral } from 'strip-literal'
import { getQuery } from 'ufo'
import type { Plugin } from '../plugin'
import type { ResolvedConfig } from '../config'
import type { ResolveFn } from '../'
import {
injectQuery,
isParentDirectory,
normalizePath,
slash,
Expand Down Expand Up @@ -59,7 +59,7 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
let [pureUrl, queryString = ''] = rawUrl.split('?')
if (queryString) {
pureUrl += '`'
queryString = '?' + queryString.replace(/`$/, '')
queryString = '?' + queryString.slice(0, -1)
}
const ast = this.parse(pureUrl)
const templateLiteral = (ast as any).body[0].expression
Expand All @@ -71,15 +71,11 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
continue
}

const query = getQuery(queryString)
const globOptions = {
eager: true,
import: 'default',
query: {
// A hack to allow 'as' & 'query' exist at the same time
url: '',
...query,
},
// A hack to allow 'as' & 'query' exist at the same time
query: injectQuery(queryString, 'url'),
}
// Note: native import.meta.url is not supported in the baseline
// target so we use the global location here. It can be
Expand Down

0 comments on commit 354c779

Please sign in to comment.