Skip to content

Commit

Permalink
wip: bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 8, 2020
1 parent 1a0c554 commit e44d77d
Show file tree
Hide file tree
Showing 23 changed files with 1,552 additions and 550 deletions.
30 changes: 30 additions & 0 deletions .github/maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Vite Maintenance Principles

## Ensure type support

Vite aims to be fully usable as a dependency in a TypeScript project (e.g. it should provide proper typings for VitePress), and also in `vite.config.ts`. This means any types that are exposed needs to be part of `dependencies` instead of `devDependencies`. For example, if a config option uses an imported type from a `@types/x` package, that type package should be included as a dependency (e.g. `@types/http-proxy`)

On the contrary, if a dependency's type isn't exposed, then its typing should be left in `devDependencies` to reduce user dependency downloads (e.g. `@types/ws`).

## Think before adding a dependency

Vite aims to be lightweight, and this includes being aware of the number of npm dependencies and their size.

Note we pre-bundle most dependencies with rollup before publishing! Therefore most non-type dependencies should be added under `devDependencies` by default.

Avoid dependencies that:

- Cannot be properly bundled due to native deps. If it must be included due to critical functionality, put it under `dependencies` (auto excluded during rollup build). Example: `esbuild`.

- Simple enought that it can be substituted with a local helper (e.g. one-function packages like `p-map-series`)

- Has large transitive dependencies that results in bloated `node_modules` size compared to the functionality it provides. For example, `http-proxy` itself plus `@types/http-proxy` is a little over 1MB in size, but `http-proxy-middleware` pulls in a ton of dependencies that makes it 7MB(!) when a minimal custom middleware on top of `http-proxy` only requires a couple lines of code.

## Think before adding yet another option

We already have many config options, and we should avoid fixing an issue by adding yet another one. Before adding an option, try to think about:

- Whether the problem is really worth addressing
- Whether the problem can be fixed with a smarter default
- Whether the problem has workaround using existing options
- Whether the problem can be addressed with a plugin instead
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
node_modules
dist
dist-ssr
dist-types
TODOs.md
*.log
temp
explorations
.idea
*.local
*.local
22 changes: 21 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@
],
"devDependencies": {
"@types/node": "^14.14.10",
"enquirer": "^2.3.6",
"execa": "^5.0.0",
"lint-staged": "^10.5.3",
"minimist": "^1.2.5",
"npm-run-all": "^4.1.5",
"typescript": "^4.1.2"
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"semver": "^7.3.4",
"typescript": "^4.1.2",
"yorkie": "^2.0.0"
},
"gitHooks": {
"pre-commit": "lint-staged",
"commit-msg": "node scripts/verifyCommit.js"
},
"lint-staged": {
"*.js": [
"prettier --write"
],
"*.ts": [
"prettier --parser=typescript --write"
]
}
}
2 changes: 1 addition & 1 deletion packages/playground/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h1>hello</h1>
<h1>hello???fesf?</h1>
<img src="/logo.png" alt="">
<script type="module" src="/test.js"></script>
4 changes: 2 additions & 2 deletions packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"scripts": {
"dev": "vite --debug",
"build": "vite build --debug",
"serve": "serve dist"
"serve": "sirv dist"
},
"devDependencies": {
"serve": "^11.3.2"
"sirv-cli": "^1.0.9"
}
}
6 changes: 5 additions & 1 deletion packages/playground/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export function hi() {
console.log('hi')
fetch('/api/todos/1')
.then((res) => res.json())
.then((data) => {
console.log(data)
})
}

hi()
13 changes: 13 additions & 0 deletions packages/playground/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from 'vite'

export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
}
})
53 changes: 53 additions & 0 deletions packages/vite/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",

"projectFolder": "./src/node",

"mainEntryPointFilePath": "./dist-types/node/index.d.ts",

"dtsRollup": {
"enabled": true,
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
},

"apiReport": {
"enabled": false
},

"docModel": {
"enabled": false
},

"tsdocMetadata": {
"enabled": false
},

"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},

"extractorMessageReporting": {
"default": {
"logLevel": "warning",
"addToApiReportFile": true
},

"ae-missing-release-tag": {
"logLevel": "none"
}
},

"tsdocMessageReporting": {
"default": {
"logLevel": "warning"
},

"tsdoc-undefined-tag": {
"logLevel": "none"
}
}
}
}
48 changes: 21 additions & 27 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
"vite": "bin/vite.js"
},
"main": "dist/node/index.js",
"types": "dist/node/index.d.ts",
"types": "dist/vite.d.ts",
"files": [
"bin",
"src",
"dist/**/*.js",
"dist/**/*.js.map",
"dist/**/*.d.ts"
"dist"
],
"engines": {
"node": ">=12.0.0"
Expand All @@ -31,49 +28,46 @@
"dev": "run-p dev-client dev-node",
"dev-client": "tsc -w --incremental --p src/client",
"dev-node": "tsc -w --incremental --p src/node",
"build": "rimraf dist && tsc -p src/client && tsc -p src/node && node scripts/patchTypes",
"build": "run-s build-src build-types",
"build-src": "rimraf dist && rollup -c",
"build-types": "tsc --emitDeclarationOnly --outDir dist-types -p src/node && api-extractor run && rimraf dist-types",
"lint": "prettier --write --parser typescript \"src/**/*.ts\"",
"pretest": "yarn build-src",
"test": "jest --clearCache && jest --runInBand --forceExit",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"release": "node scripts/release.js"
},
"gitHooks": {
"pre-commit": "lint-staged",
"commit-msg": "node scripts/verifyCommit.js"
},
"lint-staged": {
"*.js": [
"prettier --write"
],
"*.ts": [
"prettier --parser=typescript --write"
]
},
"dependencies": {
"@rollup/plugin-node-resolve": "^11.0.0",
"@types/connect": "^3.4.33",
"@types/http-proxy": "^1.17.4",
"@types/node": "^14.14.10",
"esbuild": "^0.8.20",
"rollup": "^2.34.2",
"fsevents": "~2.1.2"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.12.0",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"@rollup/plugin-typescript": "^8.0.0",
"@types/dotenv": "^8.2.0",
"@types/ws": "^7.4.0",
"acorn": "^8.0.4",
"acorn-class-fields": "^0.3.7",
"cac": "^6.6.1",
"chalk": "^4.1.0",
"cheap-watch": "^1.0.3",
"chokidar": "^3.4.3",
"connect": "^3.7.0",
"connect-history-api-fallback": "^1.6.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"dotenv-expand": "^5.1.0",
"esbuild": "^0.8.20",
"http-proxy": "^1.18.1",
"rollup": "^2.34.2",
"magic-string": "^0.25.7",
"selfsigned": "^1.10.8",
"sirv": "^1.0.10",
"source-map-support": "^0.5.19",
"ws": "^7.4.1"
},
"devDependencies": {
"@types/dotenv": "^8.2.0",
"@types/ws": "^7.4.0",
"source-map-support": "^0.5.19"
}
}
Loading

0 comments on commit e44d77d

Please sign in to comment.