提交 14ca9314 编写于 作者: fxy060608's avatar fxy060608

wip(ssr): compatible with vite@4.3.x

上级 6fb591fd
......@@ -10,7 +10,6 @@
},
"dependencies": {
"@dcloudio/uni-app": "../../uni-app",
"@dcloudio/uni-cloud": "../../uni-cloud",
"@dcloudio/uni-components": "../../uni-components",
"@dcloudio/uni-h5": "../../uni-h5",
"vue": "3.2.47",
......
......@@ -14,5 +14,5 @@ process.env.UNI_CLOUD_SPACES = JSON.stringify([
*/
export default defineConfig({
build: { minify: false },
plugins: [uni({ viteLegacyOptions: false })],
plugins: [uni({ viteLegacyOptions: false }), { name: 'ttt', configResolved(config) { console.log(config.resolve)} }],
})
......@@ -14,7 +14,7 @@ const hbxPlugins = {
export function initModuleAlias() {
const compilerSfcPath = require.resolve('@vue/compiler-sfc')
// const serverRendererPath = require.resolve('@vue/server-renderer')
const serverRendererPath = require.resolve('@vue/server-renderer')
moduleAlias.addAliases({
'@vue/shared': require.resolve('@vue/shared'),
'@vue/shared/dist/shared.esm-bundler.js': require.resolve(
......@@ -22,9 +22,9 @@ export function initModuleAlias() {
),
'@vue/compiler-dom': require.resolve('@vue/compiler-dom'),
'@vue/compiler-sfc': compilerSfcPath,
// '@vue/server-renderer': serverRendererPath,
'@vue/server-renderer': serverRendererPath,
'vue/compiler-sfc': compilerSfcPath,
// 'vue/server-renderer': serverRendererPath,
'vue/server-renderer': serverRendererPath,
})
if (process.env.VITEST) {
moduleAlias.addAliases({
......
......@@ -17,8 +17,13 @@
"url": "https://github.com/dcloudio/uni-app/issues"
},
"gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
"dependencies": {
"@dcloudio/uni-cloud": "3.0.0-alpha-3080220230428001",
"@dcloudio/uni-h5": "3.0.0-alpha-3080220230428001",
"@dcloudio/uni-i18n": "3.0.0-alpha-3080220230428001"
},
"devDependencies": {
"@dcloudio/uni-shared": "3.0.0-alpha-3080220230428001",
"@types/quill": "1.3.10"
}
}
}
\ No newline at end of file
......@@ -3,12 +3,16 @@ import type { Plugin, ResolvedConfig } from 'vite'
import { OutputChunk } from 'rollup'
import { isSsr, parseRpx2UnitOnce } from '@dcloudio/uni-cli-shared'
import {
isSsr,
parseRpx2UnitOnce,
resolveBuiltIn,
} from '@dcloudio/uni-cli-shared'
import {
initSsrAliasOnce,
initSsrDefine,
rewriteSsrVue,
rewriteSsrResolve,
rewriteSsrNativeTag,
rewriteSsrRenderStyle,
generateSsrDefineCode,
......@@ -25,10 +29,26 @@ export function uniSSRPlugin(): Plugin {
name: 'uni:h5-ssr',
config(userConfig, env) {
if (isSsr(env.command, userConfig)) {
initSsrAliasOnce()
rewriteSsrVue()
rewriteSsrResolve()
rewriteSsrNativeTag()
rewriteSsrRenderStyle(process.env.UNI_INPUT_DIR)
return {
resolve: {
alias: [
{
find: 'vue',
replacement: resolveBuiltIn(
'@dcloudio/uni-h5-vue/dist/vue.runtime.esm.js'
),
},
{
find: 'vue/server-renderer',
replacement: resolveBuiltIn('@vue/server-renderer'),
},
],
},
}
}
},
configResolved(config: ResolvedConfig) {
......
import path from 'path'
import fs from 'fs-extra'
import fs from 'fs'
import { extend, isArray, isString, NormalizedStyle } from '@vue/shared'
import {
once,
isH5NativeTag,
createRpx2Unit,
Rpx2UnitOptions,
......@@ -33,6 +34,43 @@ export function isSsrManifest(
return false
}
const SSR_ALIAS: Record<string, string> = {
vue: '@dcloudio/uni-h5-vue',
'vue/server-renderer': 'vue/server-renderer',
'@vue/server-renderer': '@vue/server-renderer',
'@dcloudio/uni-cloud': '@dcloudio/uni-cloud',
'@dcloudio/uni-h5': '@dcloudio/uni-h5',
'@dcloudio/uni-i18n': '@dcloudio/uni-i18n',
'@dcloudio/uni-shared': '@dcloudio/uni-shared',
}
export const initSsrAliasOnce = once(() => {
// 重写 package.json 的读取
const oldJoin = path.join
const alias = Object.keys(SSR_ALIAS).reduce((alias, key) => {
const newKey = oldJoin('node_modules', key, 'package.json')
if (key.endsWith('vue/server-renderer')) {
alias[newKey] = path.join(
path.dirname(resolveBuiltIn(SSR_ALIAS[key])),
'package.json'
)
} else {
alias[newKey] = resolveBuiltIn(SSR_ALIAS[key] + '/package.json')
}
return alias
}, {} as Record<string, string>)
// console.log(alias)
path.join = (...paths: string[]): string => {
let res = oldJoin.apply(path, paths)
if (res.endsWith('package.json')) {
const key = Object.keys(alias).find((key) => res.endsWith(key))
if (key) {
res = alias[key]
}
}
return res
}
})
export function initSsrDefine(config: ResolvedConfig) {
return extend(globalThis, {
__IMPORT_META_ENV_BASE_URL__: config.env.BASE_URL,
......
......@@ -5,7 +5,8 @@
"main": "dist/vue.runtime.cjs.js",
"module": "dist/vue.runtime.esm.js",
"files": [
"dist"
"dist",
"server-renderer"
],
"sideEffects": false,
"repository": {
......@@ -19,6 +20,7 @@
},
"gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
"dependencies": {
"@dcloudio/uni-shared": "3.0.0-alpha-3080220230428001"
"@dcloudio/uni-shared": "3.0.0-alpha-3080220230428001",
"@vue/server-renderer": "3.2.47"
}
}
export * from '@vue/server-renderer'
module.exports = require('@vue/server-renderer')
export * from '@vue/server-renderer'
\ No newline at end of file
{
"main": "index.js",
"module": "index.mjs",
"types": "index.d.ts"
}
\ No newline at end of file
......@@ -200,9 +200,6 @@ importers:
'@dcloudio/uni-app':
specifier: ../../uni-app
version: link:../../uni-app
'@dcloudio/uni-cloud':
specifier: ../../uni-cloud
version: link:../../uni-cloud
'@dcloudio/uni-components':
specifier: ../../uni-components
version: link:../../uni-components
......@@ -705,6 +702,16 @@ importers:
version: 3.2.11
packages/uni-components:
dependencies:
'@dcloudio/uni-cloud':
specifier: 3.0.0-alpha-3080220230428001
version: link:../uni-cloud
'@dcloudio/uni-h5':
specifier: 3.0.0-alpha-3080220230428001
version: link:../uni-h5
'@dcloudio/uni-i18n':
specifier: 3.0.0-alpha-3080220230428001
version: link:../uni-i18n
devDependencies:
'@dcloudio/uni-shared':
specifier: 3.0.0-alpha-3080220230428001
......@@ -858,6 +865,9 @@ importers:
'@dcloudio/uni-shared':
specifier: 3.0.0-alpha-3080220230428001
version: link:../uni-shared
'@vue/server-renderer':
specifier: 3.2.47
version: 3.2.47(vue@3.2.47)
packages/uni-i18n: {}
......
......@@ -25,7 +25,7 @@ const pkgs = {
next: '9.1.9',
},
vite: {
latest: '4.3.3',
latest: '4.3.4',
},
'@vitejs/plugin-vue': {
latest: '4.2.1',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册