Skip to content

Commit

Permalink
fix(optimizer): use all inputs for optimized entry matching
Browse files Browse the repository at this point in the history
fix #1769
  • Loading branch information
yyx990803 committed Jan 28, 2021
1 parent be0e698 commit 9ecf52b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions packages/vite/src/node/optimizer/index.ts
Expand Up @@ -186,15 +186,19 @@ export async function optimizeDeps(
entryToIdMap[deps[id].toLowerCase()] = id
}

const normalizedInputs = Object.keys(meta.inputs).map((input) =>
normalizePath(path.resolve(input))
)

for (const output in meta.outputs) {
if (/\.vite[\/\\]chunk\.\w+\.js$/.test(output) || output.endsWith('.map')) {
continue
}
const { inputs, exports } = meta.outputs[output]
const { exports } = meta.outputs[output]
const relativeOutput = normalizePath(
path.relative(cacheDir, path.resolve(output))
)
for (const input in inputs) {
for (const input of normalizedInputs) {
const entry = normalizePath(path.resolve(input))
if (!entry.replace(/\.mjs$/, '.js').endsWith(relativeOutput)) {
continue
Expand Down
8 changes: 4 additions & 4 deletions packages/vite/src/node/optimizer/registerMissing.ts
Expand Up @@ -49,6 +49,10 @@ export function createMissingImpoterRegisterFn(server: ViteDevServer) {
newDeps
))
knownOptimized = newData!.optimized
logger.info(
chalk.greenBright(`✨ dependencies updated, reloading page...`),
{ timestamp: true }
)
} catch (e) {
logger.error(
chalk.red(`error while updating dependencies:\n${e.stack}`),
Expand All @@ -60,10 +64,6 @@ export function createMissingImpoterRegisterFn(server: ViteDevServer) {
server._pendingReload = pendingResolve = null
}

logger.info(chalk.greenBright(`✨ dependencies updated.`), {
timestamp: true
})

// Importers' cached transform results have stale imports (resolved to
// old locations) so they need to be invalidated before the page is
// reloaded.
Expand Down

0 comments on commit 9ecf52b

Please sign in to comment.