Skip to content

Commit

Permalink
🐳 chore:
Browse files Browse the repository at this point in the history
  • Loading branch information
yuuuuuyu committed Jul 25, 2024
1 parent ef637eb commit 87efaa5
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
lockfile=false
registry=https://registry.npmjs.org/
# registry=https://registry.npmjs.org/
45 changes: 33 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
{
"name": "vite-plugin-clean",
"version": "1.0.1",
"name": "vite-plugin-cleaned",
"version": "1.0.20",
"private": false,
"description": "",
"main": "dist/vite-plugin-clean.umd.js",
"module": "dist/vite-plugin-clean.es.js",
"types": "dist/index.d.ts",
"main": "./dist/vite-plugin-cleaned.umd.js",
"module": "./dist/vite-plugin-cleaned.es.js",
"types": "./dist/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./dist/vite-plugin-cleaned.es.js",
"require": "./dist/vite-plugin-cleaned.umd.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"build": "vite build"
"build": "vite build",
"publish:patch": "npm version patch && npm publish --access public"
},
"files": [
"dist/*"
"dist",
"LICENSE",
"package.json",
"README.md"
],
"keywords": [
"vite",
Expand All @@ -22,19 +34,28 @@
"license": "ISC",
"repository": {
"type": "git",
"url": "git+https://github.com/yuuuuuyu/vite-plugin-clean.git"
"url": "git+https://github.com/yuuuuuyu/vite-plugin-cleaned.git"
},
"homepage": "https://github.com/yuuuuuyu/vite-plugin-clean#readme",
"homepage": "https://github.com/yuuuuuyu/vite-plugin-cleaned#readme",
"dependencies": {
"typescript": "^5.5.4",
"vite": "^5.3.4"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.14.11",
"fs-extra": "^11.2.0",
"chalk": "^5.3.0",
"ora": "^8.0.1",
"path": "^0.12.7",
"rollup-plugin-polyfill-node": "^0.13.0",
"vite-plugin-dts": "4.0.0-beta.1"
"vite-plugin-dts": "4.0.0-beta.1",
"vite-plugin-node-polyfills": "^0.22.0"
},
"bundledDependencies": [
"ora",
"chalk"
],
"peerDependencies": {
"ora": "^5.0.0",
"chalk": "^4.0.0"
}
}
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import ora from "ora"
import { PluginOptions } from "./types"
import { deleteFolderRecursive, log } from "./utils"

export default function vitePluginClean(options: PluginOptions): Plugin {
const { folder = "dist", hooks = {} } = options || {}
export default function vitePluginClean(options: PluginOptions = {}): Plugin {
const { folder = "dist", hooks = {} } = options
if (typeof folder !== "string" && !Array.isArray(folder)) {
throw new Error(
chalk.blue.bgRed.bold(
Expand All @@ -18,10 +18,11 @@ export default function vitePluginClean(options: PluginOptions): Plugin {
const folders = typeof folder === "string" ? [folder] : folder
let spinner = ora("Loading...")
return {
name: "vite-plugin-clean",
name: "vite-plugin-cleaned",
enforce: "pre",
async buildStart() {
log(
chalk.blue("\n[vite:clean]"),
chalk.blue("\n[vite:cleaned]"),
chalk.green(`Start cleaning: ${folders.join(", ")}`)
)
spinner = ora("Loading...").start()
Expand All @@ -30,7 +31,7 @@ export default function vitePluginClean(options: PluginOptions): Plugin {
const folderPath = path.resolve(process.cwd(), folder)
await deleteFolderRecursive(folderPath)
log(
chalk.blue("\n[vite:clean]"),
chalk.blue("\n[vite:cleaned]"),
chalk.green.bold(`Successfully deleted: ${folderPath}`)
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export type PluginOptions = {
folder: string | string[]
folder?: string | string[]
hooks?: {
buildStart?: () => void | Promise<void>
closeBundle?: () => void | Promise<void>
}
}

4 changes: 2 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path"
import fs from "fs/promises"
import path from "node:path"
import fs from "fs-extra"

export const log = console.log
export async function deleteFolderRecursive(folderPath: string) {
Expand Down
3 changes: 0 additions & 3 deletions test.js

This file was deleted.

3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"typeRoots": [
"./node_modules/@types",
],
"declaration": true, // 生成 .d.ts 文件
"outDir": "dist" // 输出目录
},
Expand Down
17 changes: 11 additions & 6 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { defineConfig } from "vite"
import polyfillNode from "rollup-plugin-polyfill-node"
import path from "path"
import dts from "vite-plugin-dts"
import vitePluginClean from "./src/index"

import { nodePolyfills } from "vite-plugin-node-polyfills"

export default defineConfig({
// optimizeDeps: {
// include: ["fs-extra", "ora", "path"],
// },
plugins: [
vitePluginClean({
folder: "dist",
Expand All @@ -14,20 +18,21 @@ export default defineConfig({
outputDir: "dist/types",
tsConfigFilePath: "./tsconfig.json",
}),
nodePolyfills(),
],
build: {
lib: {
entry: path.resolve(__dirname, "src/index.ts"),
name: "VitePluginClean",
fileName: format => `vite-plugin-clean.${format}.js`,
name: "VitePluginCleaned",
fileName: format => `vite-plugin-cleaned.${format}.js`,
},
rollupOptions: {
plugins: [polyfillNode()],
external: ["fs/promises", "ora"],
external: ["fs-extra", "ora", "chalk"],
output: {
globals: {
"fs/promises": "fs/promises",
"fs-extra": "fs-extra",
ora: "ora",
chalk: "chalk",
},
exports: "named",
},
Expand Down

0 comments on commit 87efaa5

Please sign in to comment.