diff --git a/bin/vite.js b/bin/vite.js index 831411f4ca12b4..d075ba1c48f13d 100755 --- a/bin/vite.js +++ b/bin/vite.js @@ -1,6 +1,6 @@ #!/usr/bin/env node const argv = require('minimist')(process.argv.slice(2)) -const server = require('../dist/server').createServer(argv) +const server = require('../dist').createServer(argv) let port = argv.port || 3000 diff --git a/package.json b/package.json index 79905cedfa1a17..d1ea09a91cf2cd 100644 --- a/package.json +++ b/package.json @@ -6,17 +6,17 @@ "bin": { "vite": "bin/vite.js" }, - "main": "dist/server/index.js", - "types": "dist/server/index.d.ts", + "main": "dist/node/index.js", + "types": "dist/node/index.d.ts", "files": [ "bin", "dist" ], "scripts": { - "dev": "run-p dev-client dev-server", + "dev": "run-p dev-client dev-node", "dev-client": "tsc -w --p src/client", - "dev-server": "tsc -w --p src/server", - "build": "rm -rf dist && tsc -p src/client && tsc -p src/server", + "dev-node": "tsc -w --p src/node", + "build": "rm -rf dist && tsc -p src/client && tsc -p src/node", "lint": "prettier --write --parser typescript \"src/**/*.ts\"", "test": "yarn build && jest", "prepublishOnly": "yarn build" diff --git a/src/client/tsconfig.json b/src/client/tsconfig.json index 2a9d6cea0040f7..0bf14737597a70 100644 --- a/src/client/tsconfig.json +++ b/src/client/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "outDir": "../../dist/client", + "outDir": "../../dist", "module": "esnext", "lib": ["ESNext", "DOM"] }, diff --git a/src/node/build.ts b/src/node/build.ts new file mode 100644 index 00000000000000..cc349af8b0d868 --- /dev/null +++ b/src/node/build.ts @@ -0,0 +1 @@ +export function build() {} diff --git a/src/node/index.ts b/src/node/index.ts new file mode 100644 index 00000000000000..37183651544933 --- /dev/null +++ b/src/node/index.ts @@ -0,0 +1 @@ +export * from './server' diff --git a/src/server/resolveVue.ts b/src/node/resolveVue.ts similarity index 100% rename from src/server/resolveVue.ts rename to src/node/resolveVue.ts diff --git a/src/server/index.ts b/src/node/server.ts similarity index 80% rename from src/server/index.ts rename to src/node/server.ts index 8990ac9276d176..3e04b4c6a60d3e 100644 --- a/src/server/index.ts +++ b/src/node/server.ts @@ -1,10 +1,10 @@ import http, { Server } from 'http' import Koa from 'koa' import chokidar, { FSWatcher } from 'chokidar' -import { modulesPlugin } from './plugins/modules' -import { vuePlugin } from './plugins/vue' -import { hmrPlugin } from './plugins/hmr' -import { servePlugin } from './plugins/serve' +import { modulesPlugin } from './serverPluginModules' +import { vuePlugin } from './serverPluginVue' +import { hmrPlugin } from './serverPluginHmr' +import { servePlugin } from './serverPluginServe' export type Plugin = (ctx: PluginContext) => void diff --git a/src/server/plugins/hmr.ts b/src/node/serverPluginHmr.ts similarity index 95% rename from src/server/plugins/hmr.ts rename to src/node/serverPluginHmr.ts index 35793f9882c5ec..0219539a31a81c 100644 --- a/src/server/plugins/hmr.ts +++ b/src/node/serverPluginHmr.ts @@ -28,18 +28,19 @@ // so that on the client, the `hot.accept` call would have reigstered for // updates using the full paths of the dependencies. -import { Plugin } from '../index' +import { Plugin } from './server' import path from 'path' import WebSocket from 'ws' import hash_sum from 'hash-sum' import { SFCBlock } from '@vue/compiler-sfc' -import { parseSFC, vueCache } from './vue' -import { cachedRead } from '../utils' -import { importerMap, hmrBoundariesMap } from './modules' +import { parseSFC, vueCache } from './serverPluginVue' +import { cachedRead } from './utils' +import { importerMap, hmrBoundariesMap } from './serverPluginModules' const debug = require('debug')('vite:hmr') -const hmrClientFilePath = path.resolve(__dirname, '../../client/client.js') +// client and node files are placed flat in the dist folder +const hmrClientFilePath = path.resolve(__dirname, './client.js') export const hmrClientPublicPath = '/@hmr' interface HMRPayload { diff --git a/src/server/plugins/modules.ts b/src/node/serverPluginModules.ts similarity index 98% rename from src/server/plugins/modules.ts rename to src/node/serverPluginModules.ts index 2f6b3d51cc7df8..d4e7b32c1f9eb8 100644 --- a/src/server/plugins/modules.ts +++ b/src/node/serverPluginModules.ts @@ -1,13 +1,13 @@ -import { Plugin } from '../index' -import { resolveVue } from '../resolveVue' +import { Plugin } from './server' +import { resolveVue } from './resolveVue' import path from 'path' import resolve from 'resolve-from' import { Readable } from 'stream' import { init as initLexer, parse as parseImports } from 'es-module-lexer' import MagicString from 'magic-string' -import { cachedRead } from '../utils' +import { cachedRead } from './utils' import { promises as fs } from 'fs' -import { hmrClientPublicPath } from './hmr' +import { hmrClientPublicPath } from './serverPluginHmr' import { parse } from '@babel/parser' import { StringLiteral } from '@babel/types' import LRUCache from 'lru-cache' diff --git a/src/server/plugins/serve.ts b/src/node/serverPluginServe.ts similarity index 97% rename from src/server/plugins/serve.ts rename to src/node/serverPluginServe.ts index 1d65361aa8a1ff..8c61211b2f49e5 100644 --- a/src/server/plugins/serve.ts +++ b/src/node/serverPluginServe.ts @@ -1,4 +1,4 @@ -import { Plugin } from '../index' +import { Plugin } from './server' const debug = require('debug')('vite:history') diff --git a/src/server/plugins/vue.ts b/src/node/serverPluginVue.ts similarity index 96% rename from src/server/plugins/vue.ts rename to src/node/serverPluginVue.ts index 89047ee548e4c6..5161cb5187acf6 100644 --- a/src/server/plugins/vue.ts +++ b/src/node/serverPluginVue.ts @@ -1,15 +1,15 @@ -import { Plugin } from '../index' +import { Plugin } from './server' import path from 'path' import { SFCDescriptor, SFCTemplateBlock, SFCStyleBlock } from '@vue/compiler-sfc' -import { resolveCompiler } from '../resolveVue' +import { resolveCompiler } from './resolveVue' import hash_sum from 'hash-sum' -import { cachedRead } from '../utils' +import { cachedRead } from './utils' import LRUCache from 'lru-cache' -import { hmrClientPublicPath } from './hmr' +import { hmrClientPublicPath } from './serverPluginHmr' interface CacheEntry { descriptor?: SFCDescriptor diff --git a/src/server/tsconfig.json b/src/node/tsconfig.json similarity index 80% rename from src/server/tsconfig.json rename to src/node/tsconfig.json index 5243791ff80819..343f5a1696e0d1 100644 --- a/src/server/tsconfig.json +++ b/src/node/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "outDir": "../../dist/server", + "outDir": "../../dist", "module": "commonjs", "lib": ["ESNext"] }, diff --git a/src/server/utils.ts b/src/node/utils.ts similarity index 100% rename from src/server/utils.ts rename to src/node/utils.ts