Skip to content

Commit

Permalink
fix: @vite/client http request is 404 not found(vitejs#4174)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Jul 8, 2021
1 parent d377aae commit 8435d41
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/vite/src/client/client.ts
Expand Up @@ -8,7 +8,9 @@ import {
} from 'types/hmrPayload'
import { CustomEventName } from 'types/customEvent'
import { ErrorOverlay, overlayId } from './overlay'
import './env'
// eslint-disable-next-line node/no-missing-import
import '@vite/env'
// eslint-disable-next-line node/no-missing-import

// injected by the hmr plugin when served
declare const __ROOT__: string
Expand Down
14 changes: 12 additions & 2 deletions packages/vite/src/node/config.ts
Expand Up @@ -21,7 +21,12 @@ import { ESBuildOptions } from './plugins/esbuild'
import dotenv from 'dotenv'
import dotenvExpand from 'dotenv-expand'
import { Alias, AliasOptions } from 'types/alias'
import { CLIENT_DIR, DEFAULT_ASSETS_RE } from './constants'
import {
CLIENT_PUBLIC_PATH,
CLIENT_ENTRY,
ENV_ENTRY,
DEFAULT_ASSETS_RE
} from './constants'
import {
InternalResolveOptions,
ResolveOptions,
Expand Down Expand Up @@ -294,13 +299,18 @@ export async function resolveConfig(
config.root ? path.resolve(config.root) : process.cwd()
)

const defaultAlias = [
{ find: /^[\/]?@vite\/env/, replacement: () => ENV_ENTRY },
{ find: CLIENT_PUBLIC_PATH, replacement: () => CLIENT_ENTRY }
]

// resolve alias with internal client alias
const resolvedAlias = mergeAlias(
// #1732 the CLIENT_DIR may contain $$ which cannot be used as direct
// replacement string.
// @ts-ignore because @rollup/plugin-alias' type doesn't allow function
// replacement, but its implementation does work with function values.
[{ find: /^\/@vite\//, replacement: () => CLIENT_DIR + '/' }],
defaultAlias,
config.resolve?.alias || config.alias || []
)

Expand Down

0 comments on commit 8435d41

Please sign in to comment.