Skip to content

Commit

Permalink
🐛 vite方法引入报错解决
Browse files Browse the repository at this point in the history
  • Loading branch information
lgldlk committed Aug 1, 2024
1 parent 32ae057 commit 18ad478
Show file tree
Hide file tree
Showing 4 changed files with 1,743 additions and 1,246 deletions.
21 changes: 21 additions & 0 deletions packages/cdn-script-core/lib/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from "node:path";
// Object.prototype.toString.call
function toStringCall(obj: any) {
return Object.prototype.toString.call(obj);
Expand All @@ -10,3 +11,23 @@ export function isStr(obj: any): obj is string {
export function isObject(obj: any): obj is Object {
return toStringCall(obj) === "[object Object]";
}

const windowsSlashRE = /\\/g;
/**
* Convert Windows backslash paths to slash paths: 'foo\\bar' ➔ 'foo/bar'
* @param p path
* @returns path
*/
export function slash(p: string): string {
return p.replace(windowsSlashRE, "/");
}
// 是否是windows系统
export const isWindows = typeof process !== "undefined" && process.platform === "win32";
/**
* Normalize a file path.
* @param id file path
* @returns file path
*/
export function normalizePath(id: string): string {
return path.posix.normalize(isWindows ? slash(id) : id);
}
1 change: 1 addition & 0 deletions packages/cdn-script-core/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { findUrls, getPackageDependencies } from "./findUrls";

import path from "path";
export * from "./consoleManage";
export * from "./common";
export * from "./generateScript";
export * from "./findUrls";
export * from "./ErrorTypes";
Expand Down
8 changes: 4 additions & 4 deletions packages/vite-add-cdn-script/lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BuildOptions, PluginOption, UserConfig, normalizePath } from "vite";
import { BuildOptions, PluginOption, UserConfig } from "vite";
import { EEnforce, IOptions } from "./types";
import { libName } from "./config";
import { getExternalScript } from "cdn-script-core";
import { getExternalScript, normalizePath } from "cdn-script-core";
import * as glob from "glob";
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";
function viteAddCdnScript(opt: IOptions): PluginOption {
const { customScript = {}, defaultCdns = ["jsdelivr", "unpkg"] } = opt;
let _config: UserConfig;
Expand Down
Loading

0 comments on commit 18ad478

Please sign in to comment.