@nizza/devkit 0.1.0-alpha.12 → 0.1.0-alpha.13
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/node_modules/.pnpm/@vitejs_plugin-basic-ssl@1.0.2_vite@5.0.4/node_modules/@vitejs/plugin-basic-ssl/dist/chunks/certificate.cjs +19578 -0
- package/dist/cjs/node_modules/.pnpm/@vitejs_plugin-basic-ssl@1.0.2_vite@5.0.4/node_modules/@vitejs/plugin-basic-ssl/dist/index.cjs +40 -0
- package/dist/cjs/shared/utils.cjs +2 -2
- package/dist/cjs/vitejs/config-builder/configs/base.cjs +3 -3
- package/dist/cjs/vitejs/config-builder/plugins.cjs +14 -0
- package/dist/cjs/vitejs/config-builder/shared/types.cjs +1 -0
- package/dist/esm/node_modules/.pnpm/@vitejs_plugin-basic-ssl@1.0.2_vite@5.0.4/node_modules/@vitejs/plugin-basic-ssl/dist/chunks/certificate.mjs +19576 -0
- package/dist/esm/node_modules/.pnpm/@vitejs_plugin-basic-ssl@1.0.2_vite@5.0.4/node_modules/@vitejs/plugin-basic-ssl/dist/index.mjs +35 -0
- package/dist/esm/vitejs/config-builder/configs/base.mjs +4 -4
- package/dist/esm/vitejs/config-builder/plugins.mjs +14 -1
- package/dist/esm/vitejs/config-builder/shared/types.mjs +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { promises } from 'node:fs';
|
|
3
|
+
|
|
4
|
+
const defaultCacheDir = "node_modules/.vite";
|
|
5
|
+
function viteBasicSslPlugin() {
|
|
6
|
+
return {
|
|
7
|
+
name: "vite:basic-ssl",
|
|
8
|
+
async configResolved(config) {
|
|
9
|
+
const certificate = await getCertificate((config.cacheDir ?? defaultCacheDir) + "/basic-ssl");
|
|
10
|
+
const https = () => ({ cert: certificate, key: certificate });
|
|
11
|
+
config.server.https = Object.assign({}, config.server.https, https());
|
|
12
|
+
config.preview.https = Object.assign({}, config.preview.https, https());
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
async function getCertificate(cacheDir) {
|
|
17
|
+
const cachePath = path.join(cacheDir, "_cert.pem");
|
|
18
|
+
try {
|
|
19
|
+
const [stat, content] = await Promise.all([
|
|
20
|
+
promises.stat(cachePath),
|
|
21
|
+
promises.readFile(cachePath, "utf8")
|
|
22
|
+
]);
|
|
23
|
+
if (Date.now() - stat.ctime.valueOf() > 30 * 24 * 60 * 60 * 1e3) {
|
|
24
|
+
throw new Error("cache is outdated.");
|
|
25
|
+
}
|
|
26
|
+
return content;
|
|
27
|
+
} catch {
|
|
28
|
+
const content = (await import('./chunks/certificate.mjs')).createCertificate();
|
|
29
|
+
promises.mkdir(cacheDir, { recursive: true }).then(() => promises.writeFile(cachePath, content)).catch(() => {
|
|
30
|
+
});
|
|
31
|
+
return content;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { viteBasicSslPlugin as default, getCertificate };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import { bundleAnalysisPlugin, httpsServerPlugin, basePlugins } from '../plugins.mjs';
|
|
2
4
|
import { Target, ViteMode, Flag, Stage } from '../shared/types.mjs';
|
|
3
5
|
import { getPlugins, when } from '../shared/utils/helpers.mjs';
|
|
4
6
|
import 'minimatch';
|
|
5
7
|
import '../../../shared/logger.mjs';
|
|
6
8
|
import '@nx/devkit';
|
|
7
9
|
import 'crypto';
|
|
8
|
-
import { existsSync } from 'fs';
|
|
9
|
-
import { resolve } from 'path';
|
|
10
10
|
import 'chalk';
|
|
11
11
|
import 'mri';
|
|
12
12
|
import 'vite';
|
|
@@ -30,7 +30,7 @@ const getBaseConfig = (ctx)=>{
|
|
|
30
30
|
const envFilePath = existsSync(resolve(path, 'src', envPath)) ? envPath : fallbackEnvPath;
|
|
31
31
|
return {
|
|
32
32
|
envPrefix,
|
|
33
|
-
plugins: getPlugins(ctx, basePlugins, bundleAnalysisPlugin),
|
|
33
|
+
plugins: getPlugins(ctx, basePlugins, httpsServerPlugin, bundleAnalysisPlugin),
|
|
34
34
|
resolve: {
|
|
35
35
|
alias: {
|
|
36
36
|
...when(resolveEnvs.default && !omittedStages.includes(stage), {
|
|
@@ -17,6 +17,7 @@ import 'crypto';
|
|
|
17
17
|
import 'fs';
|
|
18
18
|
import 'chalk';
|
|
19
19
|
import 'mri';
|
|
20
|
+
import viteBasicSslPlugin from '../../node_modules/.pnpm/@vitejs_plugin-basic-ssl@1.0.2_vite@5.0.4/node_modules/@vitejs/plugin-basic-ssl/dist/index.mjs';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Base plugins configuration for apps and libs.
|
|
@@ -83,5 +84,17 @@ import 'mri';
|
|
|
83
84
|
],
|
|
84
85
|
condition: ({ projectConfig })=>projectConfig.shadowDom
|
|
85
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* Use the plugin @vitejs/plugin-basic-ssl to create a SSL
|
|
89
|
+
* certificate and create https server.
|
|
90
|
+
*/ const httpsServerPlugin = {
|
|
91
|
+
generate: ()=>[
|
|
92
|
+
viteBasicSslPlugin()
|
|
93
|
+
],
|
|
94
|
+
condition: ({ viteCmd })=>{
|
|
95
|
+
console.log('🚀 ~ file: plugins.ts:92 ~ viteCmd.flags:', viteCmd.flags);
|
|
96
|
+
return viteCmd.flags?.[Flag.HTTPS];
|
|
97
|
+
}
|
|
98
|
+
};
|
|
86
99
|
|
|
87
|
-
export { basePlugins, bundleAnalysisPlugin, dtsPlugin, injectCssByJsPlugin, injectCssIntoShadowDomPlugin };
|
|
100
|
+
export { basePlugins, bundleAnalysisPlugin, dtsPlugin, httpsServerPlugin, injectCssByJsPlugin, injectCssIntoShadowDomPlugin };
|