提交 4d22a82c 编写于 作者: fxy060608's avatar fxy060608

chore(ssr): add log

上级 22345850
......@@ -5,8 +5,8 @@ const { uniInjectPlugin } = require('@dcloudio/vite-plugin-uni')
*/
const UniCloudPlugin = {
name: 'vite:uni-cloud',
config() {
initUniCloudEnv()
config(config) {
initUniCloudEnv(config)
return {
define: {
'process.env.UNI_CLOUD_PROVIDER': JSON.stringify(
......@@ -19,7 +19,7 @@ const UniCloudPlugin = {
}
},
configureServer(server) {
server.httpServer &&
if (server.httpServer) {
server.httpServer.on('listening', () => {
if (!process.UNI_CLOUD) {
return
......@@ -28,6 +28,18 @@ const UniCloudPlugin = {
initUniCloudWarningOnce()
})
})
} else {
initUniCloudWarningOnce()
}
},
closeBundle() {
if (process.env.UNI_PLATFORM === 'h5' && !process.env.UNI_SSR_CLIENT) {
console.log()
console.log(
'欢迎将H5站部署到uniCloud前端网页托管平台,高速、免费、安全、省心,详见:'
)
console.log('https://uniapp.dcloud.io/uniCloud/hosting')
}
},
}
......@@ -37,7 +49,7 @@ const initUniCloudWarningOnce = once(() => {
)
})
function initUniCloudEnv() {
function initUniCloudEnv(config) {
process.UNI_CLOUD = false
process.UNI_CLOUD_TCB = false
process.UNI_CLOUD_ALIYUN = false
......@@ -46,6 +58,7 @@ function initUniCloudEnv() {
if (!process.env.UNI_CLOUD_SPACES) {
return
}
const silent = config.build && config.build.ssr ? true : false
try {
const spaces = JSON.parse(process.env.UNI_CLOUD_SPACES)
if (Array.isArray(spaces)) {
......@@ -54,7 +67,10 @@ function initUniCloudEnv() {
process.UNI_CLOUD_ALIYUN = !!spaces.find((space) => space.clientSecret)
if (spaces.length === 1) {
const space = spaces[0]
console.log(`本项目的uniCloud使用的默认服务空间spaceId为:${space.id}`)
!silent &&
console.log(
`本项目的uniCloud使用的默认服务空间spaceId为:${space.id}`
)
}
process.env.UNI_CLOUD_PROVIDER = JSON.stringify(
spaces.map((space) => {
......@@ -83,9 +99,10 @@ function initUniCloudEnv() {
process.env.UNI_PLATFORM === 'h5' &&
process.env.NODE_ENV === 'production'
) {
console.warn(
'发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5'
)
!silent &&
console.warn(
'发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5'
)
}
}
......
......@@ -485,7 +485,7 @@ var safeAreaInsets = {
onChange,
offChange
};
var D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out = safeAreaInsets;
var out = safeAreaInsets;
const onEventPrevent = /* @__PURE__ */ withModifiers(() => {
}, ["prevent"]);
const onEventStop = /* @__PURE__ */ withModifiers(() => {
......@@ -497,10 +497,10 @@ function getWindowOffset() {
const left = parseInt(style.getPropertyValue("--window-left"));
const right = parseInt(style.getPropertyValue("--window-right"));
return {
top: top ? top + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top : 0,
bottom: bottom ? bottom + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom : 0,
left: left ? left + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left : 0,
right: right ? right + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right : 0
top: top ? top + out.top : 0,
bottom: bottom ? bottom + out.bottom : 0,
left: left ? left + out.left : 0,
right: right ? right + out.right : 0
};
}
function updateCssVar(cssVars) {
......@@ -12860,7 +12860,7 @@ function normalizePageMeta(pageMeta) {
let offset = rpx2px(refreshOptions.offset);
const {type} = navigationBar;
if (type !== "transparent" && type !== "none") {
offset += NAVBAR_HEIGHT + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top;
offset += NAVBAR_HEIGHT + out.top;
}
refreshOptions.offset = offset;
refreshOptions.height = rpx2px(refreshOptions.height);
......@@ -15051,7 +15051,7 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
const windowWidth = getWindowWidth(screenWidth);
let windowHeight = window.innerHeight;
const language = navigator.language;
const statusBarHeight = D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top;
const statusBarHeight = out.top;
let osname;
let osversion;
let model;
......@@ -15164,12 +15164,12 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
const system = `${osname} ${osversion}`;
const platform = osname.toLocaleLowerCase();
const safeArea = {
left: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left,
right: windowWidth - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right,
top: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top,
bottom: windowHeight - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom,
width: windowWidth - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right,
height: windowHeight - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom
left: out.left,
right: windowWidth - out.right,
top: out.top,
bottom: windowHeight - out.bottom,
width: windowWidth - out.left - out.right,
height: windowHeight - out.top - out.bottom
};
const {top: windowTop, bottom: windowBottom} = getWindowOffset();
windowHeight -= windowTop;
......@@ -15189,10 +15189,10 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
model,
safeArea,
safeAreaInsets: {
top: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top,
right: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right,
bottom: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom,
left: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left
top: out.top,
right: out.right,
bottom: out.bottom,
left: out.left
}
};
});
......
import fs from 'fs-extra'
import path from 'path'
import { build as buildByVite, BuildOptions } from 'vite'
import { CliOptions } from '.'
......@@ -14,27 +15,52 @@ export async function build(options: CliOptions) {
export async function buildSSR(options: CliOptions) {
const outputDir = process.env.UNI_OUTPUT_DIR
process.env.UNI_OUTPUT_DIR = path.resolve(outputDir, 'client')
const ssrClientDir = path.resolve(outputDir, 'client')
process.env.UNI_OUTPUT_DIR = ssrClientDir
const ssrBuildClientOptions: BuildOptions = cleanOptions(options)
ssrBuildClientOptions.ssrManifest = true
ssrBuildClientOptions.outDir = process.env.UNI_OUTPUT_DIR
process.env.UNI_SSR_CLIENT = 'true'
await buildByVite({
root: process.env.VITE_ROOT_DIR,
logLevel: options.logLevel,
clearScreen: options.clearScreen,
build: ssrBuildClientOptions,
})
process.env.UNI_OUTPUT_DIR = path.resolve(outputDir, 'server')
const ssrServerDir = path.resolve(outputDir, 'server')
process.env.UNI_OUTPUT_DIR = ssrServerDir
const ssrBuildServerOptions: BuildOptions = cleanOptions(options)
ssrBuildServerOptions.ssr = path.resolve(
process.env.UNI_INPUT_DIR,
'entry-server.js'
)
ssrBuildServerOptions.outDir = process.env.UNI_OUTPUT_DIR
ssrBuildServerOptions.rollupOptions = {
onwarn(warning, warn) {
if (warning.code === 'UNUSED_EXTERNAL_IMPORT') {
const { message } = warning
// ignore
if (message.includes('"resolveComponent"')) {
return
}
}
warn(warning)
},
}
process.env.UNI_SSR_CLIENT = ''
process.env.UNI_SSR_SERVER = 'true'
await buildByVite({
root: process.env.VITE_ROOT_DIR,
logLevel: options.logLevel,
clearScreen: options.clearScreen,
build: ssrBuildServerOptions,
})
// copy ssr-manfiest.json to server
const ssrManifestFile = path.join(ssrClientDir, 'ssr-manifest.json')
if (fs.existsSync(ssrManifestFile)) {
fs.copyFileSync(
ssrManifestFile,
path.join(ssrServerDir, 'ssr-manifest.json')
)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册