vike 0.4.214 → 0.4.216
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/dist/cjs/__internal/index.js +2 -2
- package/dist/cjs/node/api/build.js +14 -3
- package/dist/cjs/node/api/context.js +20 -0
- package/dist/cjs/node/api/dev.js +11 -3
- package/dist/cjs/node/api/onLoad.js +9 -0
- package/dist/cjs/node/api/{enhanceViteConfig.js → prepareViteApiCall.js} +11 -6
- package/dist/cjs/node/api/prerender.js +11 -3
- package/dist/cjs/node/api/preview.js +11 -3
- package/dist/cjs/node/api/utils.js +22 -0
- package/dist/cjs/node/cli/entry.js +8 -8
- package/dist/cjs/node/cli/onLoad.js +2 -0
- package/dist/cjs/node/plugin/index.js +2 -3
- package/dist/cjs/node/plugin/onLoad.js +2 -2
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +0 -3
- package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -5
- package/dist/cjs/node/plugin/plugins/commonConfig/pluginName.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +23 -1
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +0 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +9 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -7
- package/dist/cjs/node/plugin/plugins/previewConfig.js +0 -1
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +32 -17
- package/dist/cjs/node/prerender/runPrerender.js +5 -4
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +6 -6
- package/dist/cjs/node/runtime/index-common.js +3 -1
- package/dist/cjs/node/runtime/renderPage.js +4 -2
- package/dist/cjs/node/runtime/utils.js +1 -2
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +25 -0
- package/dist/cjs/node/runtime-dev/index.js +32 -0
- package/dist/cjs/shared/page-configs/getConfigValue.js +2 -31
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +4 -4
- package/dist/cjs/shared/page-configs/getConfigValueTyped.js +32 -0
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +135 -0
- package/dist/cjs/utils/isDocker.js +2 -2
- package/dist/cjs/utils/requireResolve.js +2 -2
- package/dist/esm/__internal/index.js +2 -2
- package/dist/esm/node/api/build.d.ts +10 -3
- package/dist/esm/node/api/build.js +14 -3
- package/dist/esm/node/api/context.d.ts +5 -0
- package/dist/esm/node/api/context.js +19 -0
- package/dist/esm/node/api/dev.d.ts +11 -2
- package/dist/esm/node/api/dev.js +11 -3
- package/dist/esm/node/api/onLoad.d.ts +2 -0
- package/dist/esm/node/api/onLoad.js +7 -0
- package/dist/esm/node/api/prepareViteApiCall.d.ts +7 -0
- package/dist/esm/node/api/{enhanceViteConfig.js → prepareViteApiCall.js} +11 -6
- package/dist/esm/node/api/prerender.d.ts +9 -1
- package/dist/esm/node/api/prerender.js +11 -3
- package/dist/esm/node/api/preview.d.ts +11 -2
- package/dist/esm/node/api/preview.js +11 -3
- package/dist/esm/node/api/{APIOptions.d.ts → types.d.ts} +3 -1
- package/dist/esm/node/api/utils.d.ts +2 -0
- package/dist/esm/node/api/utils.js +6 -0
- package/dist/esm/node/cli/entry.js +8 -8
- package/dist/esm/node/cli/onLoad.js +2 -0
- package/dist/esm/node/cli/parseCli.d.ts +1 -1
- package/dist/esm/node/plugin/index.js +3 -4
- package/dist/esm/node/plugin/onLoad.js +1 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +0 -3
- package/dist/esm/node/plugin/plugins/buildConfig.js +7 -6
- package/dist/esm/node/plugin/plugins/commonConfig/pluginName.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig/pluginName.js +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +23 -1
- package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +10 -20
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -7
- package/dist/esm/node/plugin/plugins/previewConfig.js +1 -2
- package/dist/esm/node/plugin/plugins/setGlobalContext.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +34 -19
- package/dist/esm/node/prerender/runPrerender.d.ts +5 -3
- package/dist/esm/node/prerender/runPrerender.js +6 -5
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +2 -2
- package/dist/esm/node/runtime/globalContext.js +7 -7
- package/dist/esm/node/runtime/index-common.d.ts +1 -0
- package/dist/esm/node/runtime/index-common.js +1 -0
- package/dist/esm/node/runtime/renderPage.js +5 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -2
- package/dist/esm/node/runtime/utils.js +1 -2
- package/dist/esm/node/runtime-dev/createDevMiddleware.d.ts +10 -0
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +23 -0
- package/dist/esm/node/runtime-dev/index.d.ts +3 -0
- package/dist/esm/node/runtime-dev/index.js +6 -0
- package/dist/esm/shared/page-configs/getConfigValue.d.ts +2 -8
- package/dist/esm/shared/page-configs/getConfigValue.js +1 -27
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.d.ts +2 -3
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +2 -2
- package/dist/esm/shared/page-configs/getConfigValueTyped.d.ts +9 -0
- package/dist/esm/shared/page-configs/getConfigValueTyped.js +27 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.d.ts +20 -0
- package/dist/esm/utils/assertSetup.js +130 -0
- package/dist/esm/utils/isDocker.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/utils/assertIsNotProductionRuntime.js +0 -62
- package/dist/cjs/utils/assertNodeEnv.js +0 -106
- package/dist/esm/node/api/enhanceViteConfig.d.ts +0 -6
- package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +0 -12
- package/dist/esm/utils/assertIsNotProductionRuntime.js +0 -59
- package/dist/esm/utils/assertNodeEnv.d.ts +0 -10
- package/dist/esm/utils/assertNodeEnv.js +0 -103
- /package/dist/cjs/node/api/{APIOptions.js → types.js} +0 -0
- /package/dist/esm/node/api/{APIOptions.js → types.js} +0 -0
|
@@ -14,7 +14,7 @@ exports.initGlobalContext_runPrerender = initGlobalContext_runPrerender;
|
|
|
14
14
|
exports.initGlobalContext_getGlobalContextAsync = initGlobalContext_getGlobalContextAsync;
|
|
15
15
|
exports.setGlobalContext_viteDevServer = setGlobalContext_viteDevServer;
|
|
16
16
|
exports.setGlobalContext_viteConfig = setGlobalContext_viteConfig;
|
|
17
|
-
exports.
|
|
17
|
+
exports.setGlobalContext_isViteDev = setGlobalContext_isViteDev;
|
|
18
18
|
exports.setGlobalContext_isPrerendering = setGlobalContext_isPrerendering;
|
|
19
19
|
const utils_js_1 = require("./utils.js");
|
|
20
20
|
const loadImportBuild_js_1 = require("./globalContext/loadImportBuild.js");
|
|
@@ -92,8 +92,8 @@ function assertIsNotInitilizedYet() {
|
|
|
92
92
|
// In develpoment, globalObject.viteDevServer always needs to be awaited for before initializing globalObject.globalContext
|
|
93
93
|
(0, utils_js_1.assert)(!globalObject.globalContext);
|
|
94
94
|
}
|
|
95
|
-
function
|
|
96
|
-
globalObject.
|
|
95
|
+
function setGlobalContext_isViteDev(isViteDev) {
|
|
96
|
+
globalObject.isViteDev = isViteDev;
|
|
97
97
|
}
|
|
98
98
|
function setGlobalContext_isPrerendering() {
|
|
99
99
|
globalObject.isPrerendering = true;
|
|
@@ -105,7 +105,7 @@ function getViteConfig() {
|
|
|
105
105
|
return globalObject.viteConfig ?? null;
|
|
106
106
|
}
|
|
107
107
|
async function initGlobalContext_renderPage() {
|
|
108
|
-
await initGlobalContext(!globalObject.
|
|
108
|
+
await initGlobalContext(!globalObject.isViteDev);
|
|
109
109
|
}
|
|
110
110
|
async function initGlobalContext_runPrerender() {
|
|
111
111
|
if (globalObject.initGlobalContext_runPrerender_alreadyCalled)
|
|
@@ -141,8 +141,8 @@ async function initGlobalContext(isProduction) {
|
|
|
141
141
|
(0, utils_js_1.assert)(globalObject.globalContext.isPrerendering === (globalObject.isPrerendering ?? false));
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
144
|
-
const { viteDevServer, viteConfig,
|
|
145
|
-
(0, utils_js_1.
|
|
144
|
+
const { viteDevServer, viteConfig, isPrerendering } = globalObject;
|
|
145
|
+
(0, utils_js_1.onSetupRuntime)();
|
|
146
146
|
if (!isProduction) {
|
|
147
147
|
(0, utils_js_1.assert)(viteConfig);
|
|
148
148
|
(0, utils_js_1.assert)(viteDevServer);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPageRenderer = exports._injectAssets = exports.getGlobalContextAsync = exports.getGlobalContextSync = exports.version = exports.stampPipe = exports.pipeStream = exports.pipeNodeStream = exports.pipeWebStream = exports.dangerouslySkipEscape = exports.escapeInject = exports.renderPage = void 0;
|
|
3
|
+
exports.createPageRenderer = exports._injectAssets = exports.createDevMiddleware = exports.getGlobalContextAsync = exports.getGlobalContextSync = exports.version = exports.stampPipe = exports.pipeStream = exports.pipeNodeStream = exports.pipeWebStream = exports.dangerouslySkipEscape = exports.escapeInject = exports.renderPage = void 0;
|
|
4
4
|
var renderPage_js_1 = require("./renderPage.js");
|
|
5
5
|
Object.defineProperty(exports, "renderPage", { enumerable: true, get: function () { return renderPage_js_1.renderPage; } });
|
|
6
6
|
var renderHtml_js_1 = require("./html/renderHtml.js");
|
|
@@ -16,6 +16,8 @@ Object.defineProperty(exports, "version", { enumerable: true, get: function () {
|
|
|
16
16
|
var globalContext_js_1 = require("./globalContext.js");
|
|
17
17
|
Object.defineProperty(exports, "getGlobalContextSync", { enumerable: true, get: function () { return globalContext_js_1.getGlobalContextSync; } });
|
|
18
18
|
Object.defineProperty(exports, "getGlobalContextAsync", { enumerable: true, get: function () { return globalContext_js_1.getGlobalContextAsync; } });
|
|
19
|
+
var index_js_1 = require("../runtime-dev/index.js");
|
|
20
|
+
Object.defineProperty(exports, "createDevMiddleware", { enumerable: true, get: function () { return index_js_1.createDevMiddleware; } });
|
|
19
21
|
// TODO/v1-release: remove
|
|
20
22
|
var injectAssets__public_js_1 = require("./html/injectAssets/injectAssets__public.js");
|
|
21
23
|
Object.defineProperty(exports, "_injectAssets", { enumerable: true, get: function () { return injectAssets__public_js_1.injectAssets__public; } });
|
|
@@ -37,7 +37,7 @@ exports.renderPage_addWrapper = renderPage_addWrapper;
|
|
|
37
37
|
async function renderPage(pageContextInit) {
|
|
38
38
|
(0, assertArguments_js_1.assertArguments)(...arguments);
|
|
39
39
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextInit, 'urlOriginal', 'string')); // assertUsage() already implemented at assertArguments()
|
|
40
|
-
(0, utils_js_1.
|
|
40
|
+
(0, utils_js_1.onSetupRuntime)();
|
|
41
41
|
assertIsUrl(pageContextInit.urlOriginal);
|
|
42
42
|
const urlPathnameWithBase = (0, utils_js_1.parseUrl)(pageContextInit.urlOriginal, '/').pathname;
|
|
43
43
|
assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
|
|
@@ -338,7 +338,9 @@ function assertIsUrl(urlOriginal) {
|
|
|
338
338
|
}
|
|
339
339
|
function assertIsNotViteRequest(urlPathname, urlOriginal) {
|
|
340
340
|
const isViteRequest = urlPathname.startsWith('/@vite/client') || urlPathname.startsWith('/@fs/') || urlPathname.startsWith('/__vite_ping');
|
|
341
|
-
|
|
341
|
+
if (!isViteRequest)
|
|
342
|
+
return;
|
|
343
|
+
(0, utils_js_1.assertUsage)(false, `${picocolors_1.default.code('renderPage(pageContextInit)')} called with ${picocolors_1.default.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which is unexpected because the URL ${picocolors_1.default.bold(urlOriginal)} should have already been handled by the development middleware: make sure the ${picocolors_1.default.cyan('createDevMiddleware()')} middleware is executed *before* the ${picocolors_1.default.cyan('renderPage()')} middleware, see ${picocolors_1.default.underline('https://vike.dev/renderPage')}`);
|
|
342
344
|
}
|
|
343
345
|
function normalizeUrl(pageContextInit, httpRequestId) {
|
|
344
346
|
const { trailingSlash, disableUrlNormalization, baseServer } = (0, globalContext_js_1.getGlobalContext)();
|
|
@@ -59,9 +59,8 @@ __exportStar(require("../../utils/objectKeys.js"), exports);
|
|
|
59
59
|
__exportStar(require("../../utils/objectEntries.js"), exports);
|
|
60
60
|
__exportStar(require("../../utils/objectFromEntries.js"), exports);
|
|
61
61
|
__exportStar(require("../../utils/getFileExtension.js"), exports);
|
|
62
|
-
__exportStar(require("../../utils/
|
|
62
|
+
__exportStar(require("../../utils/assertSetup.js"), exports);
|
|
63
63
|
__exportStar(require("../../utils/path-shim.js"), exports);
|
|
64
|
-
__exportStar(require("../../utils/assertNodeEnv.js"), exports);
|
|
65
64
|
__exportStar(require("../../utils/isHtml.js"), exports);
|
|
66
65
|
__exportStar(require("../../utils/warnIfErrorIsNotObject.js"), exports);
|
|
67
66
|
__exportStar(require("../../utils/stripAnsi.js"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDevMiddleware = createDevMiddleware;
|
|
4
|
+
const vite_1 = require("vite");
|
|
5
|
+
const prepareViteApiCall_js_1 = require("../api/prepareViteApiCall.js");
|
|
6
|
+
/*
|
|
7
|
+
* Create server middleware for development with HMR and lazy-transpiling.
|
|
8
|
+
*
|
|
9
|
+
* https://vike.dev/createDevMiddleware
|
|
10
|
+
*/
|
|
11
|
+
async function createDevMiddleware(options = {}) {
|
|
12
|
+
const viteConfig = {
|
|
13
|
+
...options.viteConfig,
|
|
14
|
+
server: {
|
|
15
|
+
...options.viteConfig?.server,
|
|
16
|
+
middlewareMode: options.viteConfig?.server?.middlewareMode ?? true
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
if (options.root)
|
|
20
|
+
viteConfig.root = options.root;
|
|
21
|
+
const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(viteConfig, 'dev');
|
|
22
|
+
const server = await (0, vite_1.createServer)(viteConfigEnhanced);
|
|
23
|
+
const devMiddleware = server.middlewares;
|
|
24
|
+
return { devMiddleware, viteServer: server, viteConfig: server.config };
|
|
25
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createDevMiddleware = void 0;
|
|
27
|
+
const createDevMiddleware_ = async (...args) => {
|
|
28
|
+
const p = './createDevMiddleware.js';
|
|
29
|
+
const { createDevMiddleware } = await Promise.resolve(`${p}`).then(s => __importStar(require(s)));
|
|
30
|
+
return createDevMiddleware(...args);
|
|
31
|
+
};
|
|
32
|
+
exports.createDevMiddleware = createDevMiddleware_;
|
|
@@ -1,39 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getConfigValueRuntime = getConfigValueRuntime;
|
|
7
|
-
|
|
8
|
-
const utils_js_1 = require("../utils.js");
|
|
9
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
|
-
const getConfigDefinedAt_js_1 = require("./getConfigDefinedAt.js");
|
|
11
|
-
function getConfigValueTyped(configValue, configName, type) {
|
|
12
|
-
/* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
|
|
13
|
-
// Enable users to suppress global config values by setting the local config value to null
|
|
14
|
-
if (configValue.value === null) return null
|
|
15
|
-
*/
|
|
16
|
-
const { value, definedAtData } = configValue;
|
|
17
|
-
if (type)
|
|
18
|
-
assertConfigValueType(value, type, configName, definedAtData);
|
|
19
|
-
return configValue;
|
|
20
|
-
}
|
|
4
|
+
const getConfigValueTyped_js_1 = require("./getConfigValueTyped.js");
|
|
21
5
|
function getConfigValueRuntime(pageConfig, configName, type) {
|
|
22
6
|
const configValue = pageConfig.configValues[configName];
|
|
23
7
|
if (!configValue)
|
|
24
8
|
return null;
|
|
25
|
-
return getConfigValueTyped(configValue, configName, type);
|
|
26
|
-
}
|
|
27
|
-
function assertConfigValueType(value, type, configName, definedAtData) {
|
|
28
|
-
(0, utils_js_1.assert)(value !== null);
|
|
29
|
-
const typeActual = typeof value;
|
|
30
|
-
if (typeActual === type)
|
|
31
|
-
return;
|
|
32
|
-
const valuePrintable = (0, utils_js_1.getValuePrintable)(value);
|
|
33
|
-
const problem = valuePrintable !== null
|
|
34
|
-
? `value ${picocolors_1.default.cyan(valuePrintable)}`
|
|
35
|
-
: `type ${picocolors_1.default.cyan(typeActual)}`;
|
|
36
|
-
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAtOptional)('Config', configName, definedAtData);
|
|
37
|
-
const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${picocolors_1.default.cyan(type)} instead`;
|
|
38
|
-
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
9
|
+
return (0, getConfigValueTyped_js_1.getConfigValueTyped)(configValue, configName, type);
|
|
39
10
|
}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getConfigValueBuildTime = getConfigValueBuildTime;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
(0,
|
|
5
|
+
const assertSetup_js_1 = require("../../utils/assertSetup.js");
|
|
6
|
+
const getConfigValueTyped_js_1 = require("./getConfigValueTyped.js");
|
|
7
|
+
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
8
8
|
function getConfigValueBuildTime(pageConfig, configName, type) {
|
|
9
9
|
const configValue = getConfigValue(pageConfig, configName);
|
|
10
10
|
if (!configValue)
|
|
11
11
|
return null;
|
|
12
|
-
return (0,
|
|
12
|
+
return (0, getConfigValueTyped_js_1.getConfigValueTyped)(configValue, configName, type);
|
|
13
13
|
}
|
|
14
14
|
function getConfigValue(pageConfig, configName) {
|
|
15
15
|
const { configValueSources, configValuesComputed, configDefinitions } = pageConfig;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getConfigValueTyped = getConfigValueTyped;
|
|
7
|
+
const utils_js_1 = require("../utils.js");
|
|
8
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
|
+
const getConfigDefinedAt_js_1 = require("./getConfigDefinedAt.js");
|
|
10
|
+
function getConfigValueTyped(configValue, configName, type) {
|
|
11
|
+
/* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
|
|
12
|
+
// Enable users to suppress global config values by setting the local config value to null
|
|
13
|
+
if (configValue.value === null) return null
|
|
14
|
+
*/
|
|
15
|
+
const { value, definedAtData } = configValue;
|
|
16
|
+
if (type)
|
|
17
|
+
assertConfigValueType(value, type, configName, definedAtData);
|
|
18
|
+
return configValue;
|
|
19
|
+
}
|
|
20
|
+
function assertConfigValueType(value, type, configName, definedAtData) {
|
|
21
|
+
(0, utils_js_1.assert)(value !== null);
|
|
22
|
+
const typeActual = typeof value;
|
|
23
|
+
if (typeActual === type)
|
|
24
|
+
return;
|
|
25
|
+
const valuePrintable = (0, utils_js_1.getValuePrintable)(value);
|
|
26
|
+
const problem = valuePrintable !== null
|
|
27
|
+
? `value ${picocolors_1.default.cyan(valuePrintable)}`
|
|
28
|
+
: `type ${picocolors_1.default.cyan(typeActual)}`;
|
|
29
|
+
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAtOptional)('Config', configName, definedAtData);
|
|
30
|
+
const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${picocolors_1.default.cyan(type)} instead`;
|
|
31
|
+
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
32
|
+
}
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.serializeConfigValues = serializeConfigValues;
|
|
7
|
-
const
|
|
7
|
+
const assertSetup_js_1 = require("../../../utils/assertSetup.js");
|
|
8
8
|
const utils_js_1 = require("../../../node/plugin/utils.js");
|
|
9
9
|
const addImportStatement_js_1 = require("../../../node/plugin/plugins/importUserCode/addImportStatement.js");
|
|
10
10
|
const transformPointerImports_js_1 = require("../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformPointerImports.js");
|
|
@@ -16,7 +16,7 @@ const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
|
16
16
|
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with parsePageConfigs()
|
|
17
17
|
// - vike/shared/page-configs/serialize/parsePageConfigs.ts
|
|
18
18
|
// - parsePageConfigs() is loaded on both the client- and server-side.
|
|
19
|
-
(0,
|
|
19
|
+
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
20
20
|
function serializeConfigValues(pageConfig, importStatements, isEnvMatch, { isEager }, tabspace) {
|
|
21
21
|
const lines = [];
|
|
22
22
|
tabspace += ' ';
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.assertIsNotProductionRuntime = assertIsNotProductionRuntime;
|
|
7
|
+
exports.onSetupRuntime = onSetupRuntime;
|
|
8
|
+
exports.onSetupBuild = onSetupBuild;
|
|
9
|
+
exports.onSetupPrerender = onSetupPrerender;
|
|
10
|
+
exports.setNodeEnvProduction = setNodeEnvProduction;
|
|
11
|
+
exports.markSetup_viteDevServer = markSetup_viteDevServer;
|
|
12
|
+
exports.markSetup_vitePreviewServer = markSetup_vitePreviewServer;
|
|
13
|
+
exports.markSetup_vikeVitePlugin = markSetup_vikeVitePlugin;
|
|
14
|
+
exports.markSetup_isViteDev = markSetup_isViteDev;
|
|
15
|
+
exports.markSetup_isPrerendering = markSetup_isPrerendering;
|
|
16
|
+
const assert_js_1 = require("./assert.js");
|
|
17
|
+
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
18
|
+
const debug_js_1 = require("./debug.js");
|
|
19
|
+
const getGlobalObject_js_1 = require("./getGlobalObject.js");
|
|
20
|
+
const isVitest_js_1 = require("./isVitest.js");
|
|
21
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
22
|
+
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
23
|
+
const debug = (0, debug_js_1.createDebugger)('vike:setup');
|
|
24
|
+
const setup = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertIsNotProductionRuntime.ts', {});
|
|
25
|
+
// Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
|
|
26
|
+
function assertIsNotProductionRuntime() {
|
|
27
|
+
if (debug.isActivated)
|
|
28
|
+
debug('assertIsNotProductionRuntime()', new Error().stack);
|
|
29
|
+
setup.shouldNotBeProduction = true;
|
|
30
|
+
}
|
|
31
|
+
function onSetupRuntime() {
|
|
32
|
+
if (debug.isActivated)
|
|
33
|
+
debug('assertSetup()', new Error().stack);
|
|
34
|
+
if (isTest())
|
|
35
|
+
return;
|
|
36
|
+
if (!isViteLoaded()) {
|
|
37
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
38
|
+
(0, assert_js_1.assertWarning)(!isNodeEnvDev(), `The ${getEnvDescription()}, which seems contradictory because the environment seems to be a production environment (Vite isn't loaded), see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
39
|
+
(0, assert_js_1.assertUsage)(!setup.vikeVitePlugin, "Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.");
|
|
40
|
+
// This assert() one of the main goal of this file: it ensures assertIsNotProductionRuntime()
|
|
41
|
+
(0, assert_js_1.assert)(!setup.shouldNotBeProduction);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
45
|
+
(0, assert_js_1.assertWarning)(isNodeEnvDev() || setup.vitePreviewServer || setup.isPrerendering, `The ${getEnvDescription()}, but Vite is loaded which is prohibited in production, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
46
|
+
// These two assert() calls aren't that interesting
|
|
47
|
+
(0, assert_js_1.assert)(setup.vikeVitePlugin);
|
|
48
|
+
(0, assert_js_1.assert)(setup.shouldNotBeProduction);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Ensure NODE_ENV is 'production' when building.
|
|
52
|
+
// - Used by both Vue and React for bundling minified version:
|
|
53
|
+
// - Vue: https://github.com/vuejs/core/blob/f66a75ea75c8aece065b61e2126b4c5b2338aa6e/packages/vue/index.js
|
|
54
|
+
// - React: https://github.com/facebook/react/blob/01ab35a9a731dec69995fbd28f3ac7eaad11e183/packages/react/npm/index.js
|
|
55
|
+
// - Required for React: setting NODE_ENV to a value other than 'production' triggers an error: https://github.com/vikejs/vike/issues/1469#issuecomment-1969301797
|
|
56
|
+
// - Not required for Vue: when building the app, NODE_ENV can be set to a value other than 'production', e.g. 'development'.
|
|
57
|
+
function onSetupBuild() {
|
|
58
|
+
assertUsageNodeEnvIsNotDev('building');
|
|
59
|
+
/* Not needed: Vite already sets `process.env.NODE_ENV = 'production'`
|
|
60
|
+
setNodeEnvProduction()
|
|
61
|
+
*/
|
|
62
|
+
}
|
|
63
|
+
function onSetupPrerender() {
|
|
64
|
+
markSetup_isPrerendering();
|
|
65
|
+
if (getNodeEnvValue())
|
|
66
|
+
assertUsageNodeEnvIsNotDev('pre-rendering');
|
|
67
|
+
setNodeEnvProduction();
|
|
68
|
+
}
|
|
69
|
+
function isViteLoaded() {
|
|
70
|
+
// Do we need setup.viteDevServer or setup.vitePreviewServer ?
|
|
71
|
+
return setup.viteDevServer || setup.vitePreviewServer || setup.isViteDev !== undefined;
|
|
72
|
+
}
|
|
73
|
+
function isTest() {
|
|
74
|
+
return (0, isVitest_js_1.isVitest)() || getNodeEnvValue() === 'test';
|
|
75
|
+
}
|
|
76
|
+
// Called by Vite hook configureServer()
|
|
77
|
+
function markSetup_viteDevServer() {
|
|
78
|
+
if (debug.isActivated)
|
|
79
|
+
debug('markSetup_viteDevServer()', new Error().stack);
|
|
80
|
+
setup.viteDevServer = true;
|
|
81
|
+
}
|
|
82
|
+
// Called by Vite hook configurePreviewServer()
|
|
83
|
+
function markSetup_vitePreviewServer() {
|
|
84
|
+
if (debug.isActivated)
|
|
85
|
+
debug('markSetup_vitePreviewServer()', new Error().stack);
|
|
86
|
+
setup.vitePreviewServer = true;
|
|
87
|
+
}
|
|
88
|
+
// Called by ../node/plugin/index.ts
|
|
89
|
+
function markSetup_vikeVitePlugin() {
|
|
90
|
+
if (debug.isActivated)
|
|
91
|
+
debug('markSetup_vikeVitePlugin()', new Error().stack);
|
|
92
|
+
setup.vikeVitePlugin = true;
|
|
93
|
+
}
|
|
94
|
+
// Whether Vite is loaded and whether it's in dev mode (the value returned by `isDevCheck()`)
|
|
95
|
+
function markSetup_isViteDev(isViteDev) {
|
|
96
|
+
if (debug.isActivated)
|
|
97
|
+
debug('markSetup_isViteDev()', new Error().stack);
|
|
98
|
+
setup.isViteDev = isViteDev;
|
|
99
|
+
}
|
|
100
|
+
// Called by ../node/prerender/runPrerender.ts
|
|
101
|
+
function markSetup_isPrerendering() {
|
|
102
|
+
if (debug.isActivated)
|
|
103
|
+
debug('markSetup_isPrerendering()', new Error().stack);
|
|
104
|
+
setup.isPrerendering = true;
|
|
105
|
+
}
|
|
106
|
+
function assertUsageNodeEnvIsNotDev(operation) {
|
|
107
|
+
if (!isNodeEnvDev())
|
|
108
|
+
return;
|
|
109
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
110
|
+
(0, assert_js_1.assertWarning)(false, `The ${getEnvDescription()} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
111
|
+
}
|
|
112
|
+
function getEnvDescription() {
|
|
113
|
+
const nodeEnv = getNodeEnvValue();
|
|
114
|
+
const isDev = isNodeEnvDev();
|
|
115
|
+
const envType = `${(isDev ? 'development' : 'production')} environment`;
|
|
116
|
+
const nodeEnvDesc = `environment is set to be a ${picocolors_1.default.bold(envType)} by ${picocolors_1.default.cyan(`process.env.NODE_ENV===${JSON.stringify(nodeEnv)}`)}`;
|
|
117
|
+
return nodeEnvDesc;
|
|
118
|
+
}
|
|
119
|
+
function isNodeEnvDev() {
|
|
120
|
+
const nodeEnv = getNodeEnvValue();
|
|
121
|
+
// That's quite strict, let's see if some user complains
|
|
122
|
+
return !nodeEnv || ['development', 'dev'].includes(nodeEnv);
|
|
123
|
+
}
|
|
124
|
+
function getNodeEnvValue() {
|
|
125
|
+
if (typeof process === 'undefined')
|
|
126
|
+
return null;
|
|
127
|
+
return process.env.NODE_ENV?.toLowerCase();
|
|
128
|
+
}
|
|
129
|
+
function setNodeEnvProduction() {
|
|
130
|
+
// The statement `process.env['NODE_ENV'] = 'production'` chokes webpack v4
|
|
131
|
+
const proc = process;
|
|
132
|
+
const { env } = proc;
|
|
133
|
+
env.NODE_ENV = 'production';
|
|
134
|
+
(0, assert_js_1.assert)(getNodeEnvValue() === 'production');
|
|
135
|
+
}
|
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.isDocker = isDocker;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const
|
|
9
|
-
(0,
|
|
8
|
+
const assertSetup_js_1 = require("./assertSetup.js");
|
|
9
|
+
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
10
10
|
function isDocker() {
|
|
11
11
|
return hasContainerEnv() || isDockerContainer();
|
|
12
12
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.requireResolve = requireResolve;
|
|
4
4
|
const assert_js_1 = require("./assert.js");
|
|
5
5
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
6
|
-
const
|
|
6
|
+
const assertSetup_js_1 = require("./assertSetup.js");
|
|
7
7
|
const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
|
|
8
8
|
const isScriptFile_js_1 = require("./isScriptFile.js");
|
|
9
9
|
const module_1 = require("module");
|
|
@@ -11,7 +11,7 @@ const module_1 = require("module");
|
|
|
11
11
|
const importMetaUrl = `file://${__filename}`;
|
|
12
12
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
13
13
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
14
|
-
(0,
|
|
14
|
+
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
15
15
|
// We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
16
16
|
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
17
17
|
function requireResolve(importPath, cwd) {
|
|
@@ -5,7 +5,7 @@ export { getMiddlewares };
|
|
|
5
5
|
import { route as routeInternal } from '../shared/route/index.js';
|
|
6
6
|
import { getPageFilesAll } from '../shared/getPageFiles.js';
|
|
7
7
|
import { getGlobalContext, initGlobalContext_getGlobalContextAsync } from '../node/runtime/globalContext.js';
|
|
8
|
-
import {
|
|
8
|
+
import { setNodeEnvProduction } from '../utils/assertSetup.js';
|
|
9
9
|
import { getRenderContext } from '../node/runtime/renderPage/renderPageAlreadyRouted.js';
|
|
10
10
|
/**
|
|
11
11
|
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel}
|
|
@@ -14,7 +14,7 @@ import { getRenderContext } from '../node/runtime/renderPage/renderPageAlreadyRo
|
|
|
14
14
|
* @param config
|
|
15
15
|
*/
|
|
16
16
|
async function getPagesAndRoutes() {
|
|
17
|
-
|
|
17
|
+
setNodeEnvProduction();
|
|
18
18
|
const renderContext = await getRenderContext();
|
|
19
19
|
const {
|
|
20
20
|
//
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export { build };
|
|
2
|
-
import type
|
|
2
|
+
import { type Rollup } from 'vite';
|
|
3
|
+
import type { APIOptions } from './types.js';
|
|
4
|
+
type RollupOutput = Rollup.RollupOutput | Rollup.RollupOutput[] | Rollup.RollupWatcher;
|
|
5
|
+
/**
|
|
6
|
+
* Programmatically trigger `$ vike build`
|
|
7
|
+
*
|
|
8
|
+
* https://vike.dev/api#build
|
|
9
|
+
*/
|
|
3
10
|
declare function build(options?: APIOptions): Promise<{
|
|
4
|
-
|
|
5
|
-
|
|
11
|
+
rollupOutputClient: RollupOutput;
|
|
12
|
+
rollupOutputServer: RollupOutput;
|
|
6
13
|
}>;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export { build };
|
|
2
|
-
import {
|
|
2
|
+
import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
3
3
|
import { build as buildVite } from 'vite';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike build`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#build
|
|
8
|
+
*/
|
|
4
9
|
async function build(options = {}) {
|
|
5
|
-
const { viteConfigEnhanced, configVike } = await
|
|
10
|
+
const { viteConfigEnhanced, configVike } = await prepareViteApiCall(options.viteConfig, 'build');
|
|
6
11
|
// Build client-side
|
|
7
12
|
const outputClient = await buildVite(viteConfigEnhanced);
|
|
8
13
|
// Build server-side
|
|
@@ -12,7 +17,13 @@ async function build(options = {}) {
|
|
|
12
17
|
const { runPrerenderFromAutoRun } = await import('../prerender/runPrerender.js');
|
|
13
18
|
await runPrerenderFromAutoRun(viteConfigEnhanced, true);
|
|
14
19
|
}
|
|
15
|
-
return {
|
|
20
|
+
return {
|
|
21
|
+
/* We don't return `viteConfig` because `viteConfigEnhanced` is `InlineConfig` not `ResolvedConfig`
|
|
22
|
+
viteConfig: viteConfigEnhanced,
|
|
23
|
+
*/
|
|
24
|
+
rollupOutputClient: outputClient,
|
|
25
|
+
rollupOutputServer: outputServer
|
|
26
|
+
};
|
|
16
27
|
}
|
|
17
28
|
function setSSR(viteConfig) {
|
|
18
29
|
return {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { isVikeCliOrApi };
|
|
2
|
+
// export { getOperation }
|
|
3
|
+
export { setOperation as setOperation };
|
|
4
|
+
import { assert, getGlobalObject } from './utils.js';
|
|
5
|
+
const globalObject = getGlobalObject('context.ts', {
|
|
6
|
+
apiOperation: undefined
|
|
7
|
+
});
|
|
8
|
+
function getOperation() {
|
|
9
|
+
assert(globalObject.apiOperation);
|
|
10
|
+
return globalObject.apiOperation;
|
|
11
|
+
}
|
|
12
|
+
function isVikeCliOrApi() {
|
|
13
|
+
// The CLI uses the API
|
|
14
|
+
return !!globalObject.apiOperation;
|
|
15
|
+
}
|
|
16
|
+
function setOperation(operation) {
|
|
17
|
+
assert(!globalObject.apiOperation);
|
|
18
|
+
globalObject.apiOperation = operation;
|
|
19
|
+
}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
export { dev };
|
|
2
|
-
import type
|
|
3
|
-
|
|
2
|
+
import { type ResolvedConfig, type ViteDevServer } from 'vite';
|
|
3
|
+
import type { APIOptions } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike dev`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#dev
|
|
8
|
+
*/
|
|
9
|
+
declare function dev(options?: APIOptions): Promise<{
|
|
10
|
+
viteServer: ViteDevServer;
|
|
11
|
+
viteConfig: ResolvedConfig;
|
|
12
|
+
}>;
|
package/dist/esm/node/api/dev.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
export { dev };
|
|
2
|
-
import {
|
|
2
|
+
import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
3
3
|
import { createServer } from 'vite';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike dev`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#dev
|
|
8
|
+
*/
|
|
4
9
|
async function dev(options = {}) {
|
|
5
|
-
const { viteConfigEnhanced } = await
|
|
10
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'dev');
|
|
6
11
|
const server = await createServer(viteConfigEnhanced);
|
|
7
|
-
return
|
|
12
|
+
return {
|
|
13
|
+
viteServer: server,
|
|
14
|
+
viteConfig: server.config
|
|
15
|
+
};
|
|
8
16
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { prepareViteApiCall };
|
|
2
|
+
import type { InlineConfig } from 'vite';
|
|
3
|
+
import type { Operation } from './types.js';
|
|
4
|
+
declare function prepareViteApiCall(viteConfig: InlineConfig | undefined, operation: Operation): Promise<{
|
|
5
|
+
viteConfigEnhanced: InlineConfig;
|
|
6
|
+
configVike: import("../../shared/ConfigVike.js").ConfigVikeResolved;
|
|
7
|
+
}>;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { prepareViteApiCall };
|
|
2
2
|
import { resolveConfig } from 'vite';
|
|
3
3
|
import { getConfigVike } from '../shared/getConfigVike.js';
|
|
4
4
|
import { pluginName } from '../plugin/plugins/commonConfig/pluginName.js';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { setOperation } from './context.js';
|
|
6
|
+
async function prepareViteApiCall(viteConfig = {}, operation) {
|
|
7
|
+
setOperation(operation);
|
|
8
|
+
return enhanceViteConfig(viteConfig, operation);
|
|
9
|
+
}
|
|
10
|
+
async function enhanceViteConfig(viteConfig = {}, operation) {
|
|
11
|
+
let viteConfigResolved = await resolveViteConfig(viteConfig, operation);
|
|
7
12
|
let viteConfigEnhanced = viteConfig;
|
|
8
13
|
// Add vike to plugins if not present
|
|
9
14
|
if (!viteConfigResolved.plugins.some((p) => p.name === pluginName)) {
|
|
@@ -13,7 +18,7 @@ async function enhanceViteConfig(viteConfig = {}, command) {
|
|
|
13
18
|
...viteConfig,
|
|
14
19
|
plugins: [...(viteConfig.plugins ?? []), vikePlugin()]
|
|
15
20
|
};
|
|
16
|
-
viteConfigResolved = await resolveViteConfig(viteConfigEnhanced,
|
|
21
|
+
viteConfigResolved = await resolveViteConfig(viteConfigEnhanced, operation);
|
|
17
22
|
}
|
|
18
23
|
const configVike = await getConfigVike(viteConfigResolved);
|
|
19
24
|
// TODO: enable Vike extensions to add Vite plugins
|
|
@@ -22,6 +27,6 @@ async function enhanceViteConfig(viteConfig = {}, command) {
|
|
|
22
27
|
configVike
|
|
23
28
|
};
|
|
24
29
|
}
|
|
25
|
-
async function resolveViteConfig(viteConfig,
|
|
26
|
-
return await resolveConfig(viteConfig,
|
|
30
|
+
async function resolveViteConfig(viteConfig, operation) {
|
|
31
|
+
return await resolveConfig(viteConfig, operation === 'build' || operation === 'prerender' ? 'build' : 'serve', 'custom', operation === 'dev' ? 'development' : 'production', operation === 'preview');
|
|
27
32
|
}
|