@octohash/vite-config 0.3.0 → 0.3.2
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/README.md +2 -2
- package/dist/index.d.mts +8 -3
- package/dist/index.mjs +120 -33
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
Opinionated but customizable, with built-in support for unplugin, i18n, and more.
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
pnpm add -
|
|
10
|
+
pnpm add -D @octohash/vite-config
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
@@ -58,7 +58,7 @@ interface OptionsConfig {
|
|
|
58
58
|
|
|
59
59
|
// Common Plugin
|
|
60
60
|
/**
|
|
61
|
-
* https://github.com/
|
|
61
|
+
* https://github.com/KusStar/vite-bundle-visualizer
|
|
62
62
|
* By default template path is: ./node_modules/.cache/visualizer/stats.html
|
|
63
63
|
*
|
|
64
64
|
* @default false
|
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import * as vite from 'vite';
|
|
|
2
2
|
import { AliasOptions, UserConfig, PluginOption } from 'vite';
|
|
3
3
|
import { PluginOptions as PluginOptions$1 } from '@intlify/unplugin-vue-i18n';
|
|
4
4
|
import { VitePluginFederationOptions } from '@originjs/vite-plugin-federation';
|
|
5
|
-
import { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
|
|
6
5
|
import { Options } from 'unplugin-auto-import/types';
|
|
7
6
|
import { Options as Options$1 } from 'unplugin-vue-components';
|
|
8
7
|
import { Options as Options$2 } from 'unplugin-vue-router';
|
|
@@ -45,12 +44,18 @@ interface MetadataPluginOptions {
|
|
|
45
44
|
type ProjectType = 'app' | 'lib';
|
|
46
45
|
interface CommonPluginOptions {
|
|
47
46
|
/**
|
|
48
|
-
* https://github.com/
|
|
47
|
+
* https://github.com/KusStar/vite-bundle-visualizer
|
|
49
48
|
* By default template path is: ./node_modules/.cache/visualizer/stats.html
|
|
50
49
|
*
|
|
51
50
|
* @default false
|
|
52
51
|
*/
|
|
53
|
-
visualizer?: boolean |
|
|
52
|
+
visualizer?: boolean | {
|
|
53
|
+
help?: boolean;
|
|
54
|
+
template?: 'treemap' | 'sunburst' | 'network';
|
|
55
|
+
output?: string;
|
|
56
|
+
open?: boolean;
|
|
57
|
+
config?: string;
|
|
58
|
+
};
|
|
54
59
|
/**
|
|
55
60
|
* Inject license info to output files
|
|
56
61
|
* Load license file from `package.json`, if it is a monorepo project, the root `package.json` will also be merged
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,6 @@ import v8 from 'node:v8';
|
|
|
10
10
|
import { format, inspect } from 'node:util';
|
|
11
11
|
import { defineConfig as defineConfig$1, mergeConfig } from 'vite';
|
|
12
12
|
import { findUp as findUp$2 } from 'find-up';
|
|
13
|
-
import { visualizer } from 'rollup-plugin-visualizer';
|
|
14
13
|
import { EOL } from 'node:os';
|
|
15
14
|
import Vue from '@vitejs/plugin-vue';
|
|
16
15
|
import VueJsx from '@vitejs/plugin-vue-jsx';
|
|
@@ -899,6 +898,49 @@ pp$8.isAsyncFunction = function() {
|
|
|
899
898
|
!(isIdentifierChar(after = this.input.charCodeAt(next + 8)) || after > 0xd7ff && after < 0xdc00))
|
|
900
899
|
};
|
|
901
900
|
|
|
901
|
+
pp$8.isUsingKeyword = function(isAwaitUsing, isFor) {
|
|
902
|
+
if (this.options.ecmaVersion < 17 || !this.isContextual(isAwaitUsing ? "await" : "using"))
|
|
903
|
+
{ return false }
|
|
904
|
+
|
|
905
|
+
skipWhiteSpace.lastIndex = this.pos;
|
|
906
|
+
var skip = skipWhiteSpace.exec(this.input);
|
|
907
|
+
var next = this.pos + skip[0].length;
|
|
908
|
+
|
|
909
|
+
if (lineBreak.test(this.input.slice(this.pos, next))) { return false }
|
|
910
|
+
|
|
911
|
+
if (isAwaitUsing) {
|
|
912
|
+
var awaitEndPos = next + 5 /* await */, after;
|
|
913
|
+
if (this.input.slice(next, awaitEndPos) !== "using" ||
|
|
914
|
+
awaitEndPos === this.input.length ||
|
|
915
|
+
isIdentifierChar(after = this.input.charCodeAt(awaitEndPos)) ||
|
|
916
|
+
(after > 0xd7ff && after < 0xdc00)
|
|
917
|
+
) { return false }
|
|
918
|
+
|
|
919
|
+
skipWhiteSpace.lastIndex = awaitEndPos;
|
|
920
|
+
var skipAfterUsing = skipWhiteSpace.exec(this.input);
|
|
921
|
+
if (skipAfterUsing && lineBreak.test(this.input.slice(awaitEndPos, awaitEndPos + skipAfterUsing[0].length))) { return false }
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
if (isFor) {
|
|
925
|
+
var ofEndPos = next + 2 /* of */, after$1;
|
|
926
|
+
if (this.input.slice(next, ofEndPos) === "of") {
|
|
927
|
+
if (ofEndPos === this.input.length ||
|
|
928
|
+
(!isIdentifierChar(after$1 = this.input.charCodeAt(ofEndPos)) && !(after$1 > 0xd7ff && after$1 < 0xdc00))) { return false }
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
var ch = this.input.charCodeAt(next);
|
|
933
|
+
return isIdentifierStart(ch, true) || ch === 92 // '\'
|
|
934
|
+
};
|
|
935
|
+
|
|
936
|
+
pp$8.isAwaitUsing = function(isFor) {
|
|
937
|
+
return this.isUsingKeyword(true, isFor)
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
pp$8.isUsing = function(isFor) {
|
|
941
|
+
return this.isUsingKeyword(false, isFor)
|
|
942
|
+
};
|
|
943
|
+
|
|
902
944
|
// Parse a single statement.
|
|
903
945
|
//
|
|
904
946
|
// If expecting a statement and finding a slash operator, parse a
|
|
@@ -975,6 +1017,23 @@ pp$8.parseStatement = function(context, topLevel, exports) {
|
|
|
975
1017
|
return this.parseFunctionStatement(node, true, !context)
|
|
976
1018
|
}
|
|
977
1019
|
|
|
1020
|
+
var usingKind = this.isAwaitUsing(false) ? "await using" : this.isUsing(false) ? "using" : null;
|
|
1021
|
+
if (usingKind) {
|
|
1022
|
+
if (topLevel && this.options.sourceType === "script") {
|
|
1023
|
+
this.raise(this.start, "Using declaration cannot appear in the top level when source type is `script`");
|
|
1024
|
+
}
|
|
1025
|
+
if (usingKind === "await using") {
|
|
1026
|
+
if (!this.canAwait) {
|
|
1027
|
+
this.raise(this.start, "Await using cannot appear outside of async function");
|
|
1028
|
+
}
|
|
1029
|
+
this.next();
|
|
1030
|
+
}
|
|
1031
|
+
this.next();
|
|
1032
|
+
this.parseVar(node, false, usingKind);
|
|
1033
|
+
this.semicolon();
|
|
1034
|
+
return this.finishNode(node, "VariableDeclaration")
|
|
1035
|
+
}
|
|
1036
|
+
|
|
978
1037
|
var maybeName = this.value, expr = this.parseExpression();
|
|
979
1038
|
if (starttype === types$1.name && expr.type === "Identifier" && this.eat(types$1.colon))
|
|
980
1039
|
{ return this.parseLabeledStatement(node, maybeName, expr, context) }
|
|
@@ -1050,18 +1109,19 @@ pp$8.parseForStatement = function(node) {
|
|
|
1050
1109
|
this.next();
|
|
1051
1110
|
this.parseVar(init$1, true, kind);
|
|
1052
1111
|
this.finishNode(init$1, "VariableDeclaration");
|
|
1053
|
-
|
|
1054
|
-
if (this.options.ecmaVersion >= 9) {
|
|
1055
|
-
if (this.type === types$1._in) {
|
|
1056
|
-
if (awaitAt > -1) { this.unexpected(awaitAt); }
|
|
1057
|
-
} else { node.await = awaitAt > -1; }
|
|
1058
|
-
}
|
|
1059
|
-
return this.parseForIn(node, init$1)
|
|
1060
|
-
}
|
|
1061
|
-
if (awaitAt > -1) { this.unexpected(awaitAt); }
|
|
1062
|
-
return this.parseFor(node, init$1)
|
|
1112
|
+
return this.parseForAfterInit(node, init$1, awaitAt)
|
|
1063
1113
|
}
|
|
1064
1114
|
var startsWithLet = this.isContextual("let"), isForOf = false;
|
|
1115
|
+
|
|
1116
|
+
var usingKind = this.isUsing(true) ? "using" : this.isAwaitUsing(true) ? "await using" : null;
|
|
1117
|
+
if (usingKind) {
|
|
1118
|
+
var init$2 = this.startNode();
|
|
1119
|
+
this.next();
|
|
1120
|
+
if (usingKind === "await using") { this.next(); }
|
|
1121
|
+
this.parseVar(init$2, true, usingKind);
|
|
1122
|
+
this.finishNode(init$2, "VariableDeclaration");
|
|
1123
|
+
return this.parseForAfterInit(node, init$2, awaitAt)
|
|
1124
|
+
}
|
|
1065
1125
|
var containsEsc = this.containsEsc;
|
|
1066
1126
|
var refDestructuringErrors = new DestructuringErrors;
|
|
1067
1127
|
var initPos = this.start;
|
|
@@ -1087,6 +1147,20 @@ pp$8.parseForStatement = function(node) {
|
|
|
1087
1147
|
return this.parseFor(node, init)
|
|
1088
1148
|
};
|
|
1089
1149
|
|
|
1150
|
+
// Helper method to parse for loop after variable initialization
|
|
1151
|
+
pp$8.parseForAfterInit = function(node, init, awaitAt) {
|
|
1152
|
+
if ((this.type === types$1._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init.declarations.length === 1) {
|
|
1153
|
+
if (this.options.ecmaVersion >= 9) {
|
|
1154
|
+
if (this.type === types$1._in) {
|
|
1155
|
+
if (awaitAt > -1) { this.unexpected(awaitAt); }
|
|
1156
|
+
} else { node.await = awaitAt > -1; }
|
|
1157
|
+
}
|
|
1158
|
+
return this.parseForIn(node, init)
|
|
1159
|
+
}
|
|
1160
|
+
if (awaitAt > -1) { this.unexpected(awaitAt); }
|
|
1161
|
+
return this.parseFor(node, init)
|
|
1162
|
+
};
|
|
1163
|
+
|
|
1090
1164
|
pp$8.parseFunctionStatement = function(node, isAsync, declarationPosition) {
|
|
1091
1165
|
this.next();
|
|
1092
1166
|
return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
|
|
@@ -1343,6 +1417,8 @@ pp$8.parseVar = function(node, isFor, kind, allowMissingInitializer) {
|
|
|
1343
1417
|
decl.init = this.parseMaybeAssign(isFor);
|
|
1344
1418
|
} else if (!allowMissingInitializer && kind === "const" && !(this.type === types$1._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
|
|
1345
1419
|
this.unexpected();
|
|
1420
|
+
} else if (!allowMissingInitializer && (kind === "using" || kind === "await using") && this.options.ecmaVersion >= 17 && this.type !== types$1._in && !this.isContextual("of")) {
|
|
1421
|
+
this.raise(this.lastTokEnd, ("Missing initializer in " + kind + " declaration"));
|
|
1346
1422
|
} else if (!allowMissingInitializer && decl.id.type !== "Identifier" && !(isFor && (this.type === types$1._in || this.isContextual("of")))) {
|
|
1347
1423
|
this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
|
|
1348
1424
|
} else {
|
|
@@ -1355,7 +1431,10 @@ pp$8.parseVar = function(node, isFor, kind, allowMissingInitializer) {
|
|
|
1355
1431
|
};
|
|
1356
1432
|
|
|
1357
1433
|
pp$8.parseVarId = function(decl, kind) {
|
|
1358
|
-
decl.id =
|
|
1434
|
+
decl.id = kind === "using" || kind === "await using"
|
|
1435
|
+
? this.parseIdent()
|
|
1436
|
+
: this.parseBindingAtom();
|
|
1437
|
+
|
|
1359
1438
|
this.checkLValPattern(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
|
|
1360
1439
|
};
|
|
1361
1440
|
|
|
@@ -3086,7 +3165,8 @@ pp$5.parseLiteral = function(value) {
|
|
|
3086
3165
|
var node = this.startNode();
|
|
3087
3166
|
node.value = value;
|
|
3088
3167
|
node.raw = this.input.slice(this.start, this.end);
|
|
3089
|
-
if (node.raw.charCodeAt(node.raw.length - 1) === 110)
|
|
3168
|
+
if (node.raw.charCodeAt(node.raw.length - 1) === 110)
|
|
3169
|
+
{ node.bigint = node.value != null ? node.value.toString() : node.raw.slice(0, -1).replace(/_/g, ""); }
|
|
3090
3170
|
this.next();
|
|
3091
3171
|
return this.finishNode(node, "Literal")
|
|
3092
3172
|
};
|
|
@@ -6116,11 +6196,9 @@ pp.readWord = function() {
|
|
|
6116
6196
|
// Please use the [github bug tracker][ghbt] to report issues.
|
|
6117
6197
|
//
|
|
6118
6198
|
// [ghbt]: https://github.com/acornjs/acorn/issues
|
|
6119
|
-
//
|
|
6120
|
-
// [walk]: util/walk.js
|
|
6121
6199
|
|
|
6122
6200
|
|
|
6123
|
-
var version = "8.
|
|
6201
|
+
var version = "8.15.0";
|
|
6124
6202
|
|
|
6125
6203
|
Parser.acorn = {
|
|
6126
6204
|
Parser: Parser,
|
|
@@ -8103,7 +8181,7 @@ function normalizeid(id) {
|
|
|
8103
8181
|
if (typeof id !== "string") {
|
|
8104
8182
|
id = id.toString();
|
|
8105
8183
|
}
|
|
8106
|
-
if (/(node|data|http|https|file):/.test(id)) {
|
|
8184
|
+
if (/(?:node|data|http|https|file):/.test(id)) {
|
|
8107
8185
|
return id;
|
|
8108
8186
|
}
|
|
8109
8187
|
if (BUILTIN_MODULES.has(id)) {
|
|
@@ -8137,7 +8215,7 @@ function _resolve$1(id, options = {}) {
|
|
|
8137
8215
|
throw new TypeError("input must be a `string` or `URL`");
|
|
8138
8216
|
}
|
|
8139
8217
|
}
|
|
8140
|
-
if (/(node|data|http|https):/.test(id)) {
|
|
8218
|
+
if (/(?:node|data|http|https):/.test(id)) {
|
|
8141
8219
|
return id;
|
|
8142
8220
|
}
|
|
8143
8221
|
if (BUILTIN_MODULES.has(id)) {
|
|
@@ -10221,10 +10299,10 @@ const isCwdInScope = isPackageExists("@octohash/vite-config");
|
|
|
10221
10299
|
function isPackageInScope(name) {
|
|
10222
10300
|
return isPackageExists(name, { paths: [scopeUrl] });
|
|
10223
10301
|
}
|
|
10224
|
-
async function ensurePackages(packages) {
|
|
10302
|
+
async function ensurePackages(packages, dev = true) {
|
|
10225
10303
|
if (process$1.env.CI || process$1.stdout.isTTY === false || isCwdInScope === false)
|
|
10226
10304
|
return;
|
|
10227
|
-
const pkgs = packages.filter((i) => i && !isPackageInScope(i));
|
|
10305
|
+
const pkgs = packages.filter((i) => i && !isPackageInScope(i) && !isPackageExists(i));
|
|
10228
10306
|
if (pkgs.length === 0)
|
|
10229
10307
|
return;
|
|
10230
10308
|
const p = await import('@clack/prompts');
|
|
@@ -10233,7 +10311,7 @@ async function ensurePackages(packages) {
|
|
|
10233
10311
|
});
|
|
10234
10312
|
if (result) {
|
|
10235
10313
|
const { installPackage } = await import('@antfu/install-pkg');
|
|
10236
|
-
await installPackage(pkgs, { dev
|
|
10314
|
+
await installPackage(pkgs, { dev });
|
|
10237
10315
|
}
|
|
10238
10316
|
}
|
|
10239
10317
|
|
|
@@ -10296,22 +10374,24 @@ async function generateLicenseText(options) {
|
|
|
10296
10374
|
}
|
|
10297
10375
|
|
|
10298
10376
|
async function loadCommonPlugins(options) {
|
|
10299
|
-
const { isBuild, visualizer
|
|
10377
|
+
const { isBuild, visualizer = false, license = true, federation } = options;
|
|
10300
10378
|
ensurePackages([
|
|
10301
10379
|
federation ? "@originjs/vite-plugin-federation" : void 0
|
|
10302
10380
|
]);
|
|
10303
10381
|
return await loadPlugins([
|
|
10304
10382
|
{
|
|
10305
|
-
condition: isBuild && !!visualizer
|
|
10306
|
-
plugins: () =>
|
|
10307
|
-
visualizer
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
|
|
10383
|
+
condition: isBuild && !!visualizer,
|
|
10384
|
+
plugins: async () => {
|
|
10385
|
+
const module = await import('vite-bundle-visualizer');
|
|
10386
|
+
return [
|
|
10387
|
+
module.default(
|
|
10388
|
+
typeof visualizer === "boolean" ? {
|
|
10389
|
+
output: "./node_modules/.cache/visualizer/stats.html",
|
|
10390
|
+
open: true
|
|
10391
|
+
} : visualizer
|
|
10392
|
+
)
|
|
10393
|
+
];
|
|
10394
|
+
}
|
|
10315
10395
|
},
|
|
10316
10396
|
{
|
|
10317
10397
|
condition: isBuild && !!license,
|
|
@@ -10409,6 +10489,8 @@ async function loadVuePlugins(projectType, options) {
|
|
|
10409
10489
|
devtools ? "vite-plugin-vue-devtools" : void 0,
|
|
10410
10490
|
i18n ? "@intlify/unplugin-vue-i18n" : void 0
|
|
10411
10491
|
]);
|
|
10492
|
+
if (i18n)
|
|
10493
|
+
await ensurePackages(["vue-i18n"], false);
|
|
10412
10494
|
return loadPlugins([
|
|
10413
10495
|
{
|
|
10414
10496
|
condition: true,
|
|
@@ -10437,7 +10519,8 @@ async function loadVuePlugins(projectType, options) {
|
|
|
10437
10519
|
typeof i18n === "boolean" ? {
|
|
10438
10520
|
compositionOnly: true,
|
|
10439
10521
|
fullInstall: true,
|
|
10440
|
-
runtimeOnly: true
|
|
10522
|
+
runtimeOnly: true,
|
|
10523
|
+
include: [resolve(process$1.cwd(), "i18n/**")]
|
|
10441
10524
|
} : i18n
|
|
10442
10525
|
)
|
|
10443
10526
|
];
|
|
@@ -10502,6 +10585,10 @@ async function resolveAutoImports() {
|
|
|
10502
10585
|
imports.push("@vueuse/core");
|
|
10503
10586
|
if (isPackageExists("vue-i18n"))
|
|
10504
10587
|
imports.push("vue-i18n");
|
|
10588
|
+
if (isPackageExists("@unhead/vue")) {
|
|
10589
|
+
const { unheadVueComposablesImports } = await import('@unhead/vue');
|
|
10590
|
+
imports.push(unheadVueComposablesImports);
|
|
10591
|
+
}
|
|
10505
10592
|
return imports;
|
|
10506
10593
|
}
|
|
10507
10594
|
async function resolveUIComponentResolvers() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octohash/vite-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.2",
|
|
5
5
|
"description": "Opinionated Vite config preset.",
|
|
6
6
|
"author": "jinghaihan",
|
|
7
7
|
"license": "MIT",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"dist"
|
|
32
32
|
],
|
|
33
33
|
"peerDependencies": {
|
|
34
|
+
"@unhead/vue": ">=2.0.0",
|
|
34
35
|
"vite": ">=7.0.0"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
@@ -40,10 +41,10 @@
|
|
|
40
41
|
"@vitejs/plugin-vue-jsx": "^5.1.1",
|
|
41
42
|
"find-up": "^8.0.0",
|
|
42
43
|
"pathe": "^2.0.3",
|
|
43
|
-
"rollup-plugin-visualizer": "^6.0.5",
|
|
44
44
|
"unplugin-auto-import": "^20.2.0",
|
|
45
45
|
"unplugin-vue-components": "^30.0.0",
|
|
46
46
|
"unplugin-vue-router": "^0.16.0",
|
|
47
|
+
"vite-bundle-visualizer": "^1.2.1",
|
|
47
48
|
"vite-plugin-dts": "^4.5.4",
|
|
48
49
|
"vite-plugin-dynamic-base": "^1.2.0"
|
|
49
50
|
},
|