Skip to content

Commit

Permalink
refactor: restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 23, 2020
1 parent aa7c8d0 commit 86147d1
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bin/vite.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "../../dist/client",
"outDir": "../../dist",
"module": "esnext",
"lib": ["ESNext", "DOM"]
},
Expand Down
1 change: 1 addition & 0 deletions src/node/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function build() {}
1 change: 1 addition & 0 deletions src/node/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './server'
File renamed without changes.
8 changes: 4 additions & 4 deletions src/server/index.ts → src/node/server.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 6 additions & 5 deletions src/server/plugins/hmr.ts → src/node/serverPluginHmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from '../index'
import { Plugin } from './server'

const debug = require('debug')('vite:history')

Expand Down
8 changes: 4 additions & 4 deletions src/server/plugins/vue.ts → src/node/serverPluginVue.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/server/tsconfig.json → src/node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "../../dist/server",
"outDir": "../../dist",
"module": "commonjs",
"lib": ["ESNext"]
},
Expand Down
File renamed without changes.

0 comments on commit 86147d1

Please sign in to comment.