Skip to content

Commit

Permalink
create monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
glitch-txs committed Apr 18, 2024
1 parent b87e04f commit 25ea5eb
Show file tree
Hide file tree
Showing 14 changed files with 10,723 additions and 386 deletions.
Empty file removed bin.ts
Empty file.
20 changes: 3 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
{
"name": "vite-size",
"version": "0.0.0",
"description": "Measure your build bundle size with Vite",
"main": "dist/index.js",
"bin": "dist/bin.js",
"type": "module",
"scripts": {
"dev": "pnpm run build && node dist/index.js",
"build": "npx tsc",
"watch": "npx tsc --watch"
},
"author": "glitch-txs",
"license": "MIT",
"dependencies": {
"vite": "^5.2.9"
},
"devDependencies": {
"@types/node": "^20.12.7",
"typescript": "^5.4.5"
"scripts": {
"build": "pnpm run --filter ./package build",
"size": "pnpm run --filter ./playground size"
}
}
7 changes: 7 additions & 0 deletions package/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node

import { run } from "./index.js"

const res = await run(process)

console.log(res)
30 changes: 17 additions & 13 deletions index.ts → package/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { build, type InlineConfig } from 'vite'
import { build } from 'vite'
import { promisify } from 'node:util'
import zlib from 'node:zlib'
import { resolve } from 'node:path'
import { readFile } from 'node:fs/promises'

const gzip = promisify(zlib.gzip)

Expand All @@ -10,27 +12,33 @@ interface FileInfo {
gzip: string | number
}

export async function buildVite(inlineConfig?:InlineConfig){
export async function run(process: NodeJS.Process){

const pkgJSONPath = resolve(process.cwd(), 'package.json')
const pkgJSON = JSON.parse(await readFile(pkgJSONPath, 'utf8'))

const external = process.argv.slice(process.argv.indexOf('--externals') + 1)

const filesInfo: FileInfo[] = []

type Return = Awaited<ReturnType<typeof build>>

const res: Omit<Return, 'RollupWatcher'> = await build({
root: './dist',
build: {
minify: true,
outDir: './distVite',
outDir: './dist/_vite-size',
lib: {
entry: 'test.js',
entry: pkgJSON.main,
formats: ['es']
}
},
rollupOptions: {
external
},
},
...inlineConfig
})


const { output } = (Array.isArray(res) ? res[0] : res)
const { output } = Array.isArray(res) ? res[0] : res

for (const chunkOrAsset of output) {
if (chunkOrAsset.type === 'chunk') {
Expand All @@ -48,8 +56,4 @@ export async function buildVite(inlineConfig?:InlineConfig){
}

return filesInfo
}

const filesInfo = await buildVite()

console.log(filesInfo)
}
22 changes: 22 additions & 0 deletions package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "vite-size",
"version": "0.0.0",
"description": "Measure your build bundle size with Vite",
"main": "dist/index.js",
"bin": "dist/bin.js",
"type": "module",
"scripts": {
"dev": "pnpm run build && node dist/index.js",
"build": "npx tsc",
"watch": "npx tsc --watch"
},
"author": "glitch-txs",
"license": "MIT",
"dependencies": {
"vite": "5.2.9"
},
"devDependencies": {
"@types/node": "^20.12.7",
"typescript": "^5.4.5"
}
}
Loading

0 comments on commit 25ea5eb

Please sign in to comment.