diff --git a/plugins/vite-plugin-canyon/package.json b/plugins/vite-plugin-canyon/package.json index 6f4f7675..a5db418c 100644 --- a/plugins/vite-plugin-canyon/package.json +++ b/plugins/vite-plugin-canyon/package.json @@ -1,6 +1,6 @@ { "name": "vite-plugin-canyon", - "version": "0.0.1-alpha.13", + "version": "0.0.1-alpha.14", "license": "MIT", "files": [ "dist/*" diff --git a/plugins/vite-plugin-canyon/src/index.ts b/plugins/vite-plugin-canyon/src/index.ts index ed626fc7..be6cae25 100644 --- a/plugins/vite-plugin-canyon/src/index.ts +++ b/plugins/vite-plugin-canyon/src/index.ts @@ -42,7 +42,7 @@ function instrumentedData(args: canyonPluginOptions): string { // 自动获取 instrumentCwd: args.instrumentCwd || process.cwd(), } - return `(new Function("return this")()).__canyon__ = ${JSON.stringify(canyon)}`; + return `(function () {var isBrowser = typeof window!== 'undefined';var globalObj = isBrowser? window : global;return globalObj})().__canyon__ = ${JSON.stringify(canyon)}`; } export default function canyonPlugin(opts: canyonPluginOptions = {}): Plugin {