Skip to content

Commit

Permalink
refactor: move append logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 23, 2020
1 parent 0a1d2ac commit c2c9c43
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/node/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'
import slash from 'slash'
import { cleanUrl, resolveFrom } from './utils'
import { cleanUrl, resolveFrom, queryRE } from './utils'
import {
idToFileMap,
moduleRE,
Expand Down Expand Up @@ -157,8 +157,11 @@ export function resolveBareModule(root: string, id: string, importer: string) {
)
}
}
return id
} else {
// append import query for non-js deep imports
return id + (queryRE.test(id) ? '&import' : '?import')
}
return id
}

const viteOptimizedMap = new Map()
Expand Down
7 changes: 1 addition & 6 deletions src/node/server/serverPluginModuleRewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,7 @@ export const resolveImport = (
if (bareImportRE.test(id)) {
// directly resolve bare module names to its entry path so that relative
// imports from it (including source map urls) can work correctly
let resolvedModulePath = resolveBareModule(root, id, importer)
const ext = path.extname(resolvedModulePath)
if (ext && !jsSrcRE.test(ext)) {
resolvedModulePath += `?import`
}
return `/@modules/${resolvedModulePath}`
return `/@modules/${resolveBareModule(root, id, importer)}`
} else {
let { pathname, query } = resolveRelativeRequest(importer, id)
// append an extension to extension-less imports
Expand Down

0 comments on commit c2c9c43

Please sign in to comment.