unplugin-env 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +3 -0
- package/README.zh-CN.md +3 -0
- package/dist/{chunk-ELYQVJHH.js → chunk-3MY5IADX.js} +1 -1
- package/dist/{chunk-Y45ERLIW.js → chunk-7PNJWMAM.js} +1 -1
- package/dist/{chunk-QWCQIGEO.js → chunk-IQADAXMX.js} +201 -111
- package/dist/esbuild.cjs +201 -111
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +201 -111
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +201 -111
- package/dist/nuxt.js +3 -3
- package/dist/rollup.cjs +201 -111
- package/dist/rollup.js +1 -1
- package/dist/types.d.cts +1 -2
- package/dist/types.d.ts +1 -2
- package/dist/vite.cjs +201 -111
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +201 -111
- package/dist/webpack.js +2 -2
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025 Nikkolast88 <https://github.com/nikkolast88>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# unplugin-env
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/unplugin-env)
|
|
4
|
+
[](https://github.com/Nikkolast88/unplugin-env/actions/workflows/ci.yml)
|
|
5
|
+
[](https://www.npmjs.com/package/unplugin-env)
|
|
6
|
+
[](./LICENSE)
|
|
4
7
|
|
|
5
8
|
Starter template for [unplugin](https://github.com/unjs/unplugin).
|
|
6
9
|
|
package/README.zh-CN.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# unplugin-env
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/unplugin-env)
|
|
4
|
+
[](https://github.com/Nikkolast88/unplugin-env/actions/workflows/ci.yml)
|
|
5
|
+
[](https://www.npmjs.com/package/unplugin-env)
|
|
6
|
+
[](./LICENSE)
|
|
4
7
|
|
|
5
8
|
[unplugin](https://github.com/unjs/unplugin) 的入门模板。
|
|
6
9
|
|
|
@@ -1914,7 +1914,7 @@ var require_scan = __commonJS({
|
|
|
1914
1914
|
isExtglob = false;
|
|
1915
1915
|
isGlob = false;
|
|
1916
1916
|
}
|
|
1917
|
-
let
|
|
1917
|
+
let base = str;
|
|
1918
1918
|
let prefix = "";
|
|
1919
1919
|
let glob = "";
|
|
1920
1920
|
if (start > 0) {
|
|
@@ -1922,31 +1922,31 @@ var require_scan = __commonJS({
|
|
|
1922
1922
|
str = str.slice(start);
|
|
1923
1923
|
lastIndex -= start;
|
|
1924
1924
|
}
|
|
1925
|
-
if (
|
|
1926
|
-
|
|
1925
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
1926
|
+
base = str.slice(0, lastIndex);
|
|
1927
1927
|
glob = str.slice(lastIndex);
|
|
1928
1928
|
} else if (isGlob === true) {
|
|
1929
|
-
|
|
1929
|
+
base = "";
|
|
1930
1930
|
glob = str;
|
|
1931
1931
|
} else {
|
|
1932
|
-
|
|
1932
|
+
base = str;
|
|
1933
1933
|
}
|
|
1934
|
-
if (
|
|
1935
|
-
if (isPathSeparator(
|
|
1936
|
-
|
|
1934
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
1935
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
|
1936
|
+
base = base.slice(0, -1);
|
|
1937
1937
|
}
|
|
1938
1938
|
}
|
|
1939
1939
|
if (opts.unescape === true) {
|
|
1940
1940
|
if (glob) glob = utils.removeBackslashes(glob);
|
|
1941
|
-
if (
|
|
1942
|
-
|
|
1941
|
+
if (base && backslashes === true) {
|
|
1942
|
+
base = utils.removeBackslashes(base);
|
|
1943
1943
|
}
|
|
1944
1944
|
}
|
|
1945
1945
|
const state = {
|
|
1946
1946
|
prefix,
|
|
1947
1947
|
input,
|
|
1948
1948
|
start,
|
|
1949
|
-
base
|
|
1949
|
+
base,
|
|
1950
1950
|
glob,
|
|
1951
1951
|
isBrace,
|
|
1952
1952
|
isBracket,
|
|
@@ -3499,28 +3499,28 @@ var require_tasks = __commonJS({
|
|
|
3499
3499
|
function groupPatternsByBaseDirectory(patterns) {
|
|
3500
3500
|
const group = {};
|
|
3501
3501
|
return patterns.reduce((collection, pattern) => {
|
|
3502
|
-
const
|
|
3503
|
-
if (
|
|
3504
|
-
collection[
|
|
3502
|
+
const base = utils.pattern.getBaseDirectory(pattern);
|
|
3503
|
+
if (base in collection) {
|
|
3504
|
+
collection[base].push(pattern);
|
|
3505
3505
|
} else {
|
|
3506
|
-
collection[
|
|
3506
|
+
collection[base] = [pattern];
|
|
3507
3507
|
}
|
|
3508
3508
|
return collection;
|
|
3509
3509
|
}, group);
|
|
3510
3510
|
}
|
|
3511
3511
|
exports.groupPatternsByBaseDirectory = groupPatternsByBaseDirectory;
|
|
3512
3512
|
function convertPatternGroupsToTasks(positive, negative, dynamic) {
|
|
3513
|
-
return Object.keys(positive).map((
|
|
3514
|
-
return convertPatternGroupToTask(
|
|
3513
|
+
return Object.keys(positive).map((base) => {
|
|
3514
|
+
return convertPatternGroupToTask(base, positive[base], negative, dynamic);
|
|
3515
3515
|
});
|
|
3516
3516
|
}
|
|
3517
3517
|
exports.convertPatternGroupsToTasks = convertPatternGroupsToTasks;
|
|
3518
|
-
function convertPatternGroupToTask(
|
|
3518
|
+
function convertPatternGroupToTask(base, positive, negative, dynamic) {
|
|
3519
3519
|
return {
|
|
3520
3520
|
dynamic,
|
|
3521
3521
|
positive,
|
|
3522
3522
|
negative,
|
|
3523
|
-
base
|
|
3523
|
+
base,
|
|
3524
3524
|
patterns: [].concat(positive, negative.map(utils.pattern.convertToNegativePattern))
|
|
3525
3525
|
};
|
|
3526
3526
|
}
|
|
@@ -4460,8 +4460,8 @@ var require_async3 = __commonJS({
|
|
|
4460
4460
|
onEnd(callback) {
|
|
4461
4461
|
this._emitter.once("end", callback);
|
|
4462
4462
|
}
|
|
4463
|
-
_pushToQueue(directory,
|
|
4464
|
-
const queueItem = { directory, base
|
|
4463
|
+
_pushToQueue(directory, base) {
|
|
4464
|
+
const queueItem = { directory, base };
|
|
4465
4465
|
this._queue.push(queueItem, (error) => {
|
|
4466
4466
|
if (error !== null) {
|
|
4467
4467
|
this._handleError(error);
|
|
@@ -4488,19 +4488,19 @@ var require_async3 = __commonJS({
|
|
|
4488
4488
|
this._isDestroyed = true;
|
|
4489
4489
|
this._emitter.emit("error", error);
|
|
4490
4490
|
}
|
|
4491
|
-
_handleEntry(entry,
|
|
4491
|
+
_handleEntry(entry, base) {
|
|
4492
4492
|
if (this._isDestroyed || this._isFatalError) {
|
|
4493
4493
|
return;
|
|
4494
4494
|
}
|
|
4495
4495
|
const fullpath = entry.path;
|
|
4496
|
-
if (
|
|
4497
|
-
entry.path = common.joinPathSegments(
|
|
4496
|
+
if (base !== void 0) {
|
|
4497
|
+
entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
|
|
4498
4498
|
}
|
|
4499
4499
|
if (common.isAppliedFilter(this._settings.entryFilter, entry)) {
|
|
4500
4500
|
this._emitEntry(entry);
|
|
4501
4501
|
}
|
|
4502
4502
|
if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) {
|
|
4503
|
-
this._pushToQueue(fullpath,
|
|
4503
|
+
this._pushToQueue(fullpath, base === void 0 ? void 0 : entry.path);
|
|
4504
4504
|
}
|
|
4505
4505
|
}
|
|
4506
4506
|
_emitEntry(entry) {
|
|
@@ -4608,19 +4608,19 @@ var require_sync3 = __commonJS({
|
|
|
4608
4608
|
this._handleQueue();
|
|
4609
4609
|
return this._storage;
|
|
4610
4610
|
}
|
|
4611
|
-
_pushToQueue(directory,
|
|
4612
|
-
this._queue.add({ directory, base
|
|
4611
|
+
_pushToQueue(directory, base) {
|
|
4612
|
+
this._queue.add({ directory, base });
|
|
4613
4613
|
}
|
|
4614
4614
|
_handleQueue() {
|
|
4615
4615
|
for (const item of this._queue.values()) {
|
|
4616
4616
|
this._handleDirectory(item.directory, item.base);
|
|
4617
4617
|
}
|
|
4618
4618
|
}
|
|
4619
|
-
_handleDirectory(directory,
|
|
4619
|
+
_handleDirectory(directory, base) {
|
|
4620
4620
|
try {
|
|
4621
4621
|
const entries = this._scandir(directory, this._settings.fsScandirSettings);
|
|
4622
4622
|
for (const entry of entries) {
|
|
4623
|
-
this._handleEntry(entry,
|
|
4623
|
+
this._handleEntry(entry, base);
|
|
4624
4624
|
}
|
|
4625
4625
|
} catch (error) {
|
|
4626
4626
|
this._handleError(error);
|
|
@@ -4632,16 +4632,16 @@ var require_sync3 = __commonJS({
|
|
|
4632
4632
|
}
|
|
4633
4633
|
throw error;
|
|
4634
4634
|
}
|
|
4635
|
-
_handleEntry(entry,
|
|
4635
|
+
_handleEntry(entry, base) {
|
|
4636
4636
|
const fullpath = entry.path;
|
|
4637
|
-
if (
|
|
4638
|
-
entry.path = common.joinPathSegments(
|
|
4637
|
+
if (base !== void 0) {
|
|
4638
|
+
entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
|
|
4639
4639
|
}
|
|
4640
4640
|
if (common.isAppliedFilter(this._settings.entryFilter, entry)) {
|
|
4641
4641
|
this._pushToStorage(entry);
|
|
4642
4642
|
}
|
|
4643
4643
|
if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) {
|
|
4644
|
-
this._pushToQueue(fullpath,
|
|
4644
|
+
this._pushToQueue(fullpath, base === void 0 ? void 0 : entry.path);
|
|
4645
4645
|
}
|
|
4646
4646
|
}
|
|
4647
4647
|
_pushToStorage(entry) {
|
|
@@ -5530,14 +5530,14 @@ var require_out4 = __commonJS({
|
|
|
5530
5530
|
|
|
5531
5531
|
// src/index.ts
|
|
5532
5532
|
import { promises as fs3 } from "fs";
|
|
5533
|
-
import
|
|
5533
|
+
import process6 from "process";
|
|
5534
5534
|
import { createUnplugin } from "unplugin";
|
|
5535
5535
|
|
|
5536
5536
|
// src/core/compress.ts
|
|
5537
5537
|
import fs from "fs";
|
|
5538
5538
|
import path from "path";
|
|
5539
5539
|
import process3 from "process";
|
|
5540
|
-
import
|
|
5540
|
+
import { Zip } from "zip-lib";
|
|
5541
5541
|
|
|
5542
5542
|
// node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
5543
5543
|
var ANSI_BACKGROUND_OFFSET = 10;
|
|
@@ -6049,39 +6049,37 @@ var Log = class {
|
|
|
6049
6049
|
};
|
|
6050
6050
|
|
|
6051
6051
|
// src/core/compress.ts
|
|
6052
|
-
async function createCompress(options) {
|
|
6053
|
-
const {
|
|
6052
|
+
async function createCompress(options, outDir) {
|
|
6053
|
+
const { ignoreBase } = options;
|
|
6054
6054
|
const zipFilePath = path.resolve(process3.cwd(), `${path.basename(outDir)}.zip`);
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
archive.finalize();
|
|
6078
|
-
} catch (error) {
|
|
6079
|
-
Log.error("Error compressing the directory", error);
|
|
6080
|
-
throw error;
|
|
6081
|
-
}
|
|
6082
|
-
});
|
|
6055
|
+
const absoluteOutDir = path.resolve(outDir);
|
|
6056
|
+
Log.log("Compressing directory:", absoluteOutDir);
|
|
6057
|
+
try {
|
|
6058
|
+
const zip = new Zip();
|
|
6059
|
+
if (ignoreBase) {
|
|
6060
|
+
zip.addFolder(absoluteOutDir);
|
|
6061
|
+
} else {
|
|
6062
|
+
zip.addFolder(absoluteOutDir, path.basename(outDir));
|
|
6063
|
+
}
|
|
6064
|
+
await zip.archive(zipFilePath);
|
|
6065
|
+
const stat = fs.statSync(zipFilePath);
|
|
6066
|
+
const size = stat.size;
|
|
6067
|
+
const readableSize = size > 1024 * 1024 ? `${(size / 1024 / 1024).toFixed(1)} MB` : `${(size / 1024).toFixed(1)} KB`;
|
|
6068
|
+
Log.success(
|
|
6069
|
+
"Successfully compressed to:",
|
|
6070
|
+
`${zipFilePath} (${readableSize})`
|
|
6071
|
+
);
|
|
6072
|
+
return null;
|
|
6073
|
+
} catch (error) {
|
|
6074
|
+
Log.error("Compression error:", error);
|
|
6075
|
+
throw error;
|
|
6076
|
+
}
|
|
6083
6077
|
}
|
|
6084
6078
|
|
|
6079
|
+
// src/core/options.ts
|
|
6080
|
+
import process5 from "process";
|
|
6081
|
+
import { deepMerge } from "@antfu/utils";
|
|
6082
|
+
|
|
6085
6083
|
// src/core/generate.ts
|
|
6086
6084
|
var import_fast_glob = __toESM(require_out4(), 1);
|
|
6087
6085
|
import { promises as fs2 } from "fs";
|
|
@@ -6102,14 +6100,15 @@ function mergeObjects(prodObj, devObj) {
|
|
|
6102
6100
|
}
|
|
6103
6101
|
}
|
|
6104
6102
|
}
|
|
6105
|
-
async function generateScript(options,
|
|
6103
|
+
async function generateScript(options, context) {
|
|
6106
6104
|
const { dir, fileName, globalName, serve, build } = options.env;
|
|
6107
6105
|
const folder = await findFolder(process4.cwd(), dir);
|
|
6108
6106
|
const files = await (0, import_fast_glob.default)("*.+(js|ts)", {
|
|
6109
6107
|
absolute: true,
|
|
6110
6108
|
cwd: folder
|
|
6111
6109
|
});
|
|
6112
|
-
const
|
|
6110
|
+
const { mode, base } = context;
|
|
6111
|
+
const testReg = mode === "dev" ? serve : build;
|
|
6113
6112
|
let target = "";
|
|
6114
6113
|
let source = "";
|
|
6115
6114
|
let code = "";
|
|
@@ -6138,7 +6137,7 @@ ${versionInfo}`;
|
|
|
6138
6137
|
const formatCode = code;
|
|
6139
6138
|
return {
|
|
6140
6139
|
code,
|
|
6141
|
-
script: ` <script type="text/javascript" src="${
|
|
6140
|
+
script: ` <script type="text/javascript" src="${base}${fileName}"></script>
|
|
6142
6141
|
</head>`,
|
|
6143
6142
|
emit: {
|
|
6144
6143
|
type: "asset",
|
|
@@ -6150,7 +6149,7 @@ ${versionInfo}`;
|
|
|
6150
6149
|
}
|
|
6151
6150
|
async function generateVersion(options, mode) {
|
|
6152
6151
|
const pkg = await getPackageInfo(process4.cwd());
|
|
6153
|
-
return `console.info("Version: %c${pkg?.version}%c - ${mode === "
|
|
6152
|
+
return `console.info("Version: %c${pkg?.version}%c - ${mode === "dev" ? "runtime" : "built"} on %c${options.datetime}%c", "color: green;", '', "color: blue;", '')`;
|
|
6154
6153
|
}
|
|
6155
6154
|
async function findFolder(directoryPath, dir) {
|
|
6156
6155
|
const ignore = /* @__PURE__ */ new Set(["dist", "node_modules", "playground", "example", "test", "jest", "tests", "locales", "public", ".git", ".github", ".vscode"]);
|
|
@@ -6174,7 +6173,6 @@ async function findFolder(directoryPath, dir) {
|
|
|
6174
6173
|
}
|
|
6175
6174
|
|
|
6176
6175
|
// src/core/options.ts
|
|
6177
|
-
import { deepMerge } from "@antfu/utils";
|
|
6178
6176
|
function resolveOptions(options) {
|
|
6179
6177
|
const defaults = {
|
|
6180
6178
|
env: {
|
|
@@ -6185,8 +6183,7 @@ function resolveOptions(options) {
|
|
|
6185
6183
|
build: /prod/i
|
|
6186
6184
|
},
|
|
6187
6185
|
compress: {
|
|
6188
|
-
|
|
6189
|
-
ignoreBase: true
|
|
6186
|
+
ignoreBase: false
|
|
6190
6187
|
}
|
|
6191
6188
|
};
|
|
6192
6189
|
const mergeOptions = deepMerge(defaults, options);
|
|
@@ -6196,67 +6193,160 @@ function resolveOptions(options) {
|
|
|
6196
6193
|
});
|
|
6197
6194
|
return {
|
|
6198
6195
|
...mergeOptions,
|
|
6199
|
-
|
|
6196
|
+
datetime: formatter.format(/* @__PURE__ */ new Date())
|
|
6200
6197
|
};
|
|
6201
6198
|
}
|
|
6199
|
+
function createUnifiedContext(resolved) {
|
|
6200
|
+
const ctx = {
|
|
6201
|
+
framework: "",
|
|
6202
|
+
base: "/",
|
|
6203
|
+
outDir: "dist",
|
|
6204
|
+
mode: "build",
|
|
6205
|
+
scriptInfo: {
|
|
6206
|
+
code: "",
|
|
6207
|
+
script: "",
|
|
6208
|
+
emit: {
|
|
6209
|
+
type: "asset",
|
|
6210
|
+
source: "",
|
|
6211
|
+
fileName: ""
|
|
6212
|
+
},
|
|
6213
|
+
watchFiles: []
|
|
6214
|
+
},
|
|
6215
|
+
get isDev() {
|
|
6216
|
+
return this.mode === "dev";
|
|
6217
|
+
},
|
|
6218
|
+
get isBuild() {
|
|
6219
|
+
return this.mode === "build";
|
|
6220
|
+
},
|
|
6221
|
+
// --- VITE ---
|
|
6222
|
+
async setVite(config) {
|
|
6223
|
+
this.framework = "vite";
|
|
6224
|
+
this.base = config.base || "/";
|
|
6225
|
+
this.outDir = config.build?.outDir || "dist";
|
|
6226
|
+
this.mode = config.command === "serve" ? "dev" : "build";
|
|
6227
|
+
ctx.scriptInfo = await generateScript(resolved, ctx);
|
|
6228
|
+
},
|
|
6229
|
+
// --- ROLLUP ---
|
|
6230
|
+
async setRollup(options) {
|
|
6231
|
+
this.framework = "rollup";
|
|
6232
|
+
this.outDir = options.dir || "dist";
|
|
6233
|
+
this.mode = process5.env.ROLLUP_WATCH ? "dev" : "build";
|
|
6234
|
+
ctx.scriptInfo = await generateScript(resolved, ctx);
|
|
6235
|
+
},
|
|
6236
|
+
// --- WEBPACK ---
|
|
6237
|
+
async setWebpack(compiler) {
|
|
6238
|
+
this.framework = "webpack";
|
|
6239
|
+
this.base = compiler.options.output?.publicPath || "/";
|
|
6240
|
+
this.outDir = compiler.options.output?.path || "dist";
|
|
6241
|
+
const raw = compiler.options.mode || "production";
|
|
6242
|
+
this.mode = raw === "development" ? "dev" : "build";
|
|
6243
|
+
ctx.scriptInfo = await generateScript(resolved, ctx);
|
|
6244
|
+
},
|
|
6245
|
+
// --- RSPACK ---
|
|
6246
|
+
async setRspack(compiler) {
|
|
6247
|
+
this.framework = "rspack";
|
|
6248
|
+
this.base = compiler.options.output?.publicPath || "/";
|
|
6249
|
+
this.outDir = compiler.options.output?.path || "dist";
|
|
6250
|
+
const raw = compiler.options.mode || "production";
|
|
6251
|
+
this.mode = raw === "development" ? "dev" : "build";
|
|
6252
|
+
ctx.scriptInfo = await generateScript(resolved, ctx);
|
|
6253
|
+
},
|
|
6254
|
+
// --- ESBUILD ---
|
|
6255
|
+
async setEsbuild(build) {
|
|
6256
|
+
this.framework = "esbuild";
|
|
6257
|
+
this.outDir = build.initialOptions.outdir || "dist";
|
|
6258
|
+
this.mode = build.initialOptions.watch ? "dev" : "build";
|
|
6259
|
+
ctx.scriptInfo = await generateScript(resolved, ctx);
|
|
6260
|
+
},
|
|
6261
|
+
// --- FARM ---
|
|
6262
|
+
async setFarm(compiler) {
|
|
6263
|
+
this.framework = "farm";
|
|
6264
|
+
this.base = compiler.config.output?.publicPath || "/";
|
|
6265
|
+
this.outDir = compiler.config.output?.path || "dist";
|
|
6266
|
+
const raw = compiler.config.mode || "production";
|
|
6267
|
+
this.mode = raw === "development" ? "dev" : "build";
|
|
6268
|
+
ctx.scriptInfo = await generateScript(resolved, ctx);
|
|
6269
|
+
},
|
|
6270
|
+
// --- ROLLDOWN ---
|
|
6271
|
+
async setRolldown(options) {
|
|
6272
|
+
this.framework = "rolldown";
|
|
6273
|
+
this.outDir = options.dir || "dist";
|
|
6274
|
+
this.mode = process5.env.ROLLDOWN_WATCH ? "dev" : "build";
|
|
6275
|
+
ctx.scriptInfo = await generateScript(resolved, ctx);
|
|
6276
|
+
}
|
|
6277
|
+
};
|
|
6278
|
+
return ctx;
|
|
6279
|
+
}
|
|
6202
6280
|
|
|
6203
6281
|
// src/index.ts
|
|
6204
6282
|
var virtualEnvId = "virtual:env";
|
|
6205
6283
|
var resolvedVirtualEnvId = `\0${virtualEnvId}`;
|
|
6206
|
-
var base = "";
|
|
6207
6284
|
var unpluginFactory = (options = {}) => {
|
|
6208
6285
|
const resolved = resolveOptions(options);
|
|
6286
|
+
const ctx = createUnifiedContext(resolved);
|
|
6209
6287
|
return [{
|
|
6210
|
-
name: "plugin-env
|
|
6211
|
-
apply: "serve",
|
|
6288
|
+
name: "plugin-env",
|
|
6212
6289
|
enforce: "post",
|
|
6213
|
-
|
|
6214
|
-
|
|
6290
|
+
rollup: {
|
|
6291
|
+
outputOptions(outputOptions) {
|
|
6292
|
+
ctx.setRollup(outputOptions);
|
|
6293
|
+
return outputOptions;
|
|
6294
|
+
}
|
|
6215
6295
|
},
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6296
|
+
vite: {
|
|
6297
|
+
async configResolved(config) {
|
|
6298
|
+
await ctx.setVite(config);
|
|
6299
|
+
}
|
|
6219
6300
|
},
|
|
6220
|
-
async
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6301
|
+
async webpack(compiler) {
|
|
6302
|
+
await ctx.setWebpack(compiler);
|
|
6303
|
+
},
|
|
6304
|
+
rspack: async (compiler) => {
|
|
6305
|
+
await ctx.setRspack(compiler);
|
|
6306
|
+
},
|
|
6307
|
+
esbuild: {
|
|
6308
|
+
async setup(build) {
|
|
6309
|
+
await ctx.setEsbuild(build);
|
|
6227
6310
|
}
|
|
6228
|
-
}
|
|
6229
|
-
}, {
|
|
6230
|
-
name: "unplugin-env-build",
|
|
6231
|
-
apply: "build",
|
|
6232
|
-
enforce: "post",
|
|
6233
|
-
configResolved(config) {
|
|
6234
|
-
base = config.base;
|
|
6235
6311
|
},
|
|
6236
|
-
|
|
6312
|
+
async farm(compiler) {
|
|
6313
|
+
await ctx.setFarm(compiler);
|
|
6314
|
+
},
|
|
6315
|
+
rolldown: {
|
|
6316
|
+
async outputOptions(outputOptions) {
|
|
6317
|
+
await ctx.setRolldown(outputOptions);
|
|
6318
|
+
}
|
|
6319
|
+
},
|
|
6320
|
+
async resolveId(id) {
|
|
6237
6321
|
if (id.startsWith(virtualEnvId))
|
|
6238
6322
|
return resolvedVirtualEnvId;
|
|
6239
6323
|
},
|
|
6240
6324
|
async load(id) {
|
|
6241
|
-
const { emit, script } =
|
|
6242
|
-
if (
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6325
|
+
const { code, watchFiles, emit, script } = ctx.scriptInfo;
|
|
6326
|
+
if (ctx.isDev) {
|
|
6327
|
+
if (id.startsWith(resolvedVirtualEnvId)) {
|
|
6328
|
+
watchFiles.forEach((file) => {
|
|
6329
|
+
this.addWatchFile(file);
|
|
6330
|
+
});
|
|
6331
|
+
return code;
|
|
6332
|
+
}
|
|
6333
|
+
} else {
|
|
6334
|
+
if (id.startsWith(resolvedVirtualEnvId)) {
|
|
6335
|
+
this.emitFile(emit);
|
|
6336
|
+
return "";
|
|
6337
|
+
}
|
|
6338
|
+
if (id.endsWith(".html")) {
|
|
6339
|
+
let code2 = await fs3.readFile(id, "utf-8");
|
|
6340
|
+
code2 = code2.replace(/<\/head>/g, script);
|
|
6341
|
+
return { code: code2 };
|
|
6342
|
+
}
|
|
6252
6343
|
}
|
|
6253
|
-
return null;
|
|
6254
6344
|
},
|
|
6255
6345
|
buildEnd: () => {
|
|
6256
|
-
|
|
6346
|
+
process6.on("beforeExit", async () => {
|
|
6257
6347
|
const { compress } = resolved;
|
|
6258
|
-
await createCompress(compress);
|
|
6259
|
-
|
|
6348
|
+
await createCompress(compress, ctx.outDir);
|
|
6349
|
+
process6.exit(0);
|
|
6260
6350
|
});
|
|
6261
6351
|
}
|
|
6262
6352
|
}];
|