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

feat: support plugin-legacy

上级 caa87deb
......@@ -5605,7 +5605,8 @@ let uniCloud$3 = new UniCloud();
(() => {
{
let defaultSpace = {};
const providers = process.env.UNI_CLOUD_PROVIDER&&JSON.parse(process.env.UNI_CLOUD_PROVIDER)||[]
const cloudProvider = process.env.UNI_CLOUD_PROVIDER
const providers = cloudProvider && JSON.parse(cloudProvider)||[]
if (providers.length === 1) {
defaultSpace = providers[0];
uniCloud$3 = uniCloud$3.init(defaultSpace);
......
......@@ -61,8 +61,10 @@ function init() {
function define() {
return {
'process.env.UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER,
'process.env.UNICLOUD_DEBUG': process.env.UNICLOUD_DEBUG,
'process.env.UNI_CLOUD_PROVIDER': JSON.stringify(
process.env.UNI_CLOUD_PROVIDER
),
'process.env.UNICLOUD_DEBUG': JSON.stringify(process.env.UNICLOUD_DEBUG),
}
}
......
......@@ -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) {
......@@ -1181,7 +1181,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);
......@@ -14352,7 +14352,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;
......@@ -14465,12 +14465,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;
......@@ -14490,10 +14490,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
}
};
});
......
......@@ -413,14 +413,3 @@ export default {
}
}
</script>
<style>
uni-ad {
display: block;
overflow: hidden;
}
uni-ad[hidden] {
display: none;
}
</style>
uni-ad {
display: block;
overflow: hidden;
}
uni-ad[hidden] {
display: none;
}
......@@ -12,7 +12,11 @@ import { createBuild } from './build'
import { createOptimizeDeps } from './optimizeDeps'
import { createDefine } from './define'
import { initPluginVueOptions } from '../vue'
import {
initPluginViteLegacyOptions,
initPluginVueJsxOptions,
initPluginVueOptions,
} from '../vue'
function normalizeRoot(config: UserConfig) {
return normalizePath(config.root ? path.resolve(config.root) : process.cwd())
......@@ -29,12 +33,18 @@ export function createConfig(
options.platform = (process.env.UNI_PLATFORM as UniApp.PLATFORM) || 'h5'
options.inputDir = normalizeInputDir(config)
options.vueOptions = initPluginVueOptions(options)
options.vueJsxOptions = initPluginVueJsxOptions(options)
options.viteLegacyOptions = initPluginViteLegacyOptions(options)
options.compiler.init()
const define = createDefine(options, config, env)
const { h5 } = parseManifestJsonOnce(options.inputDir)
let base = config.base
if (!base) {
const { h5 } = parseManifestJsonOnce(options.inputDir)
base = (h5 && h5.router && h5.router.base) || ''
}
return {
base: (h5 && h5.router && h5.router.base) || '',
publicDir: false,
base,
publicDir: config.publicDir || false,
define: extend(define, options.compiler.define()),
resolve: createResolve(options, config),
optimizeDeps: createOptimizeDeps(options),
......
......@@ -3,6 +3,8 @@ import { extend } from '@vue/shared'
import { Plugin, ResolvedConfig } from 'vite'
import { FilterPattern } from '@rollup/pluginutils'
import vue from '@vitejs/plugin-vue'
import VueJsxPlugin from '@vitejs/plugin-vue-jsx'
import ViteLegacyPlugin from '@vitejs/plugin-legacy'
import { API_DEPS_CSS } from '@dcloudio/uni-cli-shared'
......@@ -84,6 +86,15 @@ const uniInjectPluginOptions: Partial<InjectOptions> = {
})
},
}
let vueJsxPlugin: typeof VueJsxPlugin | undefined
try {
vueJsxPlugin = require('@vitejs/plugin-vue-jsx')
} catch (e) {}
let viteLegacyPlugin: typeof ViteLegacyPlugin | undefined
try {
viteLegacyPlugin = require('@vitejs/plugin-legacy')
} catch (e) {}
export function initPlugins(
config: ResolvedConfig,
......@@ -91,7 +102,6 @@ export function initPlugins(
) {
const command = config.command
const plugins = config.plugins as Plugin[]
addPlugin(plugins, vue(options.vueOptions), 'vite:uni', 'pre')
addPlugin(plugins, uniResolveIdPlugin(options), 'vite:resolve', 'pre')
......@@ -160,6 +170,25 @@ export function initPlugins(
if (command === 'build' && !config.build.ssr) {
addPlugin(plugins, uniCopyPlugin(options), plugins.length)
}
if (viteLegacyPlugin && options.viteLegacyOptions !== false) {
;(
viteLegacyPlugin(options.viteLegacyOptions) as unknown as Plugin[]
).forEach((plugin) => {
if (!plugin.apply || plugin.apply === command) {
if (plugin.enforce === 'post') {
addPlugin(plugins, plugin, 'vite:import-analysis', 'pre')
} else {
addPlugin(plugins, plugin, 'vite:vue', 'pre')
}
}
})
}
if (vueJsxPlugin && options.vueJsxOptions !== false) {
addPlugin(plugins, vueJsxPlugin(options.vueJsxOptions), 'vite:vue', 'post')
}
if (process.env.DEBUG) {
debugPlugin(plugins.length)
debugPlugin(plugins.map((p) => (p as Plugin).name))
......
......@@ -85,10 +85,7 @@ export function uniSSRPlugin(
const chunk = bundle['entry-server.js'] as OutputChunk
if (chunk) {
chunk.code =
generateSSRDefineCode(
config.define!,
parseRpx2UnitOnce(options.inputDir)
) +
generateSSRDefineCode(config, parseRpx2UnitOnce(options.inputDir)) +
'\n' +
chunk.code
}
......
import { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
import { UniCompiler, initUniCompiler } from '@dcloudio/uni-cli-shared'
import { Options as VueOptions } from '@vitejs/plugin-vue'
import { Options as ViteLegacyOptions } from '@vitejs/plugin-legacy'
import { VueJSXPluginOptions } from '@vue/babel-plugin-jsx'
import { createConfig } from './config'
import { createConfigResolved } from './configResolved'
......@@ -10,6 +12,8 @@ export interface VitePluginUniOptions {
inputDir?: string
outputDir?: string
vueOptions?: VueOptions
vueJsxOptions?: VueJSXPluginOptions
viteLegacyOptions?: ViteLegacyOptions
}
export interface VitePluginUniResolvedOptions extends VitePluginUniOptions {
base: string
......
import fs from 'fs'
import path from 'path'
import { ConfigEnv } from 'vite'
import { extend, isArray } from '@vue/shared'
import { extend, isArray, isString } from '@vue/shared'
interface ProjectFeatures {}
interface PagesFeatures {
......@@ -278,7 +278,12 @@ export function initFeatures(options: InitFeaturesOptions) {
}
// ssr nodejs features
if (options.ssr) {
extend(globalThis, features)
Object.keys(features).forEach((name) => {
const value = features[name as keyof typeof features]
extend(globalThis, {
[name]: isString(value) ? JSON.parse(value) : value,
})
})
}
return features
}
......@@ -34,7 +34,9 @@ export function isSsrManifest(
}
export function initSsrDefine(config: ResolvedConfig) {
extend(globalThis, { __IMPORT_META_ENV_BASE_URL__: config.env.BASE_URL })
return extend(globalThis, {
__IMPORT_META_ENV_BASE_URL__: config.env.BASE_URL,
})
}
function serializeDefine(define: Record<string, any>): string {
......@@ -42,21 +44,29 @@ function serializeDefine(define: Record<string, any>): string {
for (const key in define) {
const val = define[key]
res += `${JSON.stringify(key)}: ${
typeof val === 'string' && !key.startsWith('process.env.') // process.env.* 必须序列化为字符串
? `(${val})`
: JSON.stringify(val)
typeof val === 'string' ? `(${val})` : JSON.stringify(val)
}, `
}
return res + `}`
}
export function generateSSRDefineCode(
define: Record<string, any>,
config: ResolvedConfig,
{ unit, unitRatio, unitPrecision }: Rpx2UnitOptions
): string {
return fs
.readFileSync(path.join(__dirname, '../../lib/ssr/define.js'), 'utf8')
.replace('__DEFINES__', serializeDefine(define))
.replace(
'__DEFINES__',
serializeDefine(
extend(
{
__IMPORT_META_ENV_BASE_URL__: JSON.stringify(config.env.BASE_URL),
},
config.define!
)
)
)
.replace('__UNIT__', JSON.stringify(unit))
.replace('__UNIT_RATIO__', JSON.stringify(unitRatio))
.replace('__UNIT_PRECISION__', JSON.stringify(unitPrecision))
......
export * from './compilerOptions'
export * from './options'
import { extend, isArray } from '@vue/shared'
import { extend, hasOwn, isArray } from '@vue/shared'
import { CompilerOptions, SFCTemplateCompileOptions } from '@vue/compiler-sfc'
import { isNativeTag } from '@dcloudio/uni-shared'
import { isCustomElement, isNativeTag } from '@dcloudio/uni-shared'
import { EXTNAME_VUE_RE, parseCompatConfigOnce } from '@dcloudio/uni-cli-shared'
import { matchMedia } from './transforms/matchMedia'
......@@ -67,3 +67,20 @@ export function initPluginVueOptions(options: VitePluginUniResolvedOptions) {
compilerOptions.nodeTransforms.unshift(matchMedia)
return vueOptions
}
export function initPluginVueJsxOptions(options: VitePluginUniResolvedOptions) {
const vueJsxOptions = options.vueJsxOptions || (options.vueJsxOptions = {})
if (!hasOwn(vueJsxOptions, 'optimize')) {
vueJsxOptions.optimize = true
}
vueJsxOptions.isCustomElement = isCustomElement
return vueJsxOptions
}
export function initPluginViteLegacyOptions(
options: VitePluginUniResolvedOptions
) {
const viteLegacyOptions =
options.viteLegacyOptions || (options.viteLegacyOptions = {})
return viteLegacyOptions
}
......@@ -262,6 +262,11 @@
"@babel/helper-plugin-utils" "^7.13.0"
"@babel/plugin-syntax-typescript" "^7.12.13"
"@babel/standalone@^7.13.12":
version "7.14.2"
resolved "https://registry.yarnpkg.com/@babel/standalone/-/standalone-7.14.2.tgz#e198b3bc830efca0856ff977fba646ab30f90192"
integrity sha512-GGq4uU6jCZDXxHFhXtYrS/h0/W5JoiKmkBXyCM+XuL1P7lRCaQ7Ro3F0pkW2dbLknW/fg1UyAzlg0Jz1m4JBww==
"@babel/template@^7.0.0", "@babel/template@^7.12.13", "@babel/template@^7.3.3":
version "7.12.13"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.12.13.tgz#530265be8a2589dbb37523844c5bcb55947fb327"
......@@ -935,6 +940,17 @@
"@typescript-eslint/types" "4.23.0"
eslint-visitor-keys "^2.0.0"
"@vitejs/plugin-legacy@^1.3.4":
version "1.3.4"
resolved "https://registry.yarnpkg.com/@vitejs/plugin-legacy/-/plugin-legacy-1.3.4.tgz#0618bc2e92af97deb07dfb2d32b7aa2528123d66"
integrity sha512-T6+eo9Je05i45atk/e2ONiaULf5IFYgQ7UOQN9mu9lITVk9Oxe7v5h56vN8ZsN1g52/UBXRlG99nQw4CgKJFDQ==
dependencies:
"@babel/standalone" "^7.13.12"
core-js "^3.8.2"
magic-string "^0.25.7"
regenerator-runtime "^0.13.7"
systemjs "^6.8.3"
"@vitejs/plugin-vue-jsx@^1.1.4":
version "1.1.4"
resolved "https://registry.yarnpkg.com/@vitejs/plugin-vue-jsx/-/plugin-vue-jsx-1.1.4.tgz#3af194202f9ed38a7384f7a7c72f5b66ce863859"
......@@ -1721,6 +1737,11 @@ copy-descriptor@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
core-js@^3.8.2:
version "3.12.1"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.12.1.tgz#6b5af4ff55616c08a44d386f1f510917ff204112"
integrity sha512-Ne9DKPHTObRuB09Dru5AjwKjY4cJHVGu+y5f7coGn1E9Grkc3p2iBwE9AI/nJzsE29mQF7oq+mhYYRqOMFN1Bw==
core-util-is@1.0.2, core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
......@@ -4514,6 +4535,11 @@ readable-stream@~1.0.26, readable-stream@~1.0.26-4:
isarray "0.0.1"
string_decoder "~0.10.x"
regenerator-runtime@^0.13.7:
version "0.13.7"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55"
integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==
regex-not@^1.0.0, regex-not@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c"
......@@ -5159,6 +5185,11 @@ symbol-tree@^3.2.4:
version "3.2.4"
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"
systemjs@^6.8.3:
version "6.9.0"
resolved "https://registry.yarnpkg.com/systemjs/-/systemjs-6.9.0.tgz#f01a0093d4d70332fff59f2e5ff385de28284ff5"
integrity sha512-THLzcb7WzoW0I+tHB4PQge0BqqN+CAUQJ9gPc1MieqD1gnhxNUKYrhRlN5ov94saOYVVR5NZFQqQhnxi9/WEGg==
table@^6.0.4:
version "6.7.0"
resolved "https://registry.yarnpkg.com/table/-/table-6.7.0.tgz#26274751f0ee099c547f6cb91d3eff0d61d155b2"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册