feat: add mobile specific resolver functionality
This commit is contained in:
parent
0427362226
commit
d9e15de48e
|
|
@ -18,6 +18,24 @@ config.resolver.nodeModulesPaths = [
|
|||
path.resolve(__dirname, "../../node_modules"),
|
||||
]
|
||||
|
||||
config.resolver.resolveRequest = (context, moduleName, platform) => {
|
||||
const result = context.resolveRequest(context, moduleName, platform)
|
||||
if (result.type === "sourceFile") {
|
||||
const lastDotIndex = result.filePath.lastIndexOf(".")
|
||||
const mobilePath = `${result.filePath.slice(0, lastDotIndex)}.mobile${result.filePath.slice(lastDotIndex)}`
|
||||
const file = context.fileSystemLookup(mobilePath)
|
||||
if (file.exists) {
|
||||
return {
|
||||
...result,
|
||||
filePath: mobilePath,
|
||||
}
|
||||
} else {
|
||||
return result
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
module.exports = wrapWithReanimatedMetroConfig(
|
||||
withNativeWind(config, { input: "./src/global.css" }),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,26 +1,4 @@
|
|||
const imageRefererMatches = [
|
||||
{
|
||||
url: /^https:\/\/\w+\.sinaimg.cn/,
|
||||
referer: "https://weibo.com",
|
||||
},
|
||||
{
|
||||
url: /^https:\/\/i\.pximg\.net/,
|
||||
referer: "https://www.pixiv.net",
|
||||
},
|
||||
{
|
||||
url: /^https:\/\/cdnfile\.sspai\.com/,
|
||||
referer: "https://sspai.com",
|
||||
},
|
||||
{
|
||||
url: /^https:\/\/(?:\w|-)+\.cdninstagram\.com/,
|
||||
referer: "https://www.instagram.com",
|
||||
},
|
||||
{
|
||||
url: /^https:\/\/sp1\.piokok\.com/,
|
||||
referer: "https://www.piokok.com",
|
||||
force: true,
|
||||
},
|
||||
]
|
||||
import { imageRefererMatches } from "@follow/shared/src/image"
|
||||
|
||||
const isValidUrl = (url: string) => {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
export const env = {}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
import { createEnv } from "@t3-oss/env-core"
|
||||
import { z } from "zod"
|
||||
|
||||
export const isDev =
|
||||
"process" in globalThis ? process.env.NODE_ENV === "development" : import.meta.env.DEV
|
||||
export const env = createEnv({
|
||||
clientPrefix: "VITE_",
|
||||
client: {
|
||||
VITE_WEB_URL: z.string().url().default("https://app.follow.is"),
|
||||
VITE_API_URL: z.string(),
|
||||
VITE_DEV_PROXY: z.string().optional(),
|
||||
VITE_SENTRY_DSN: z.string().optional(),
|
||||
VITE_INBOXES_EMAIL: z.string().default("@follow.re"),
|
||||
VITE_FIREBASE_CONFIG: z.string().optional(),
|
||||
|
||||
VITE_OPENPANEL_CLIENT_ID: z.string().optional(),
|
||||
VITE_OPENPANEL_API_URL: z.string().url().optional(),
|
||||
|
||||
// For external, use api_url if you don't want to fill it in.
|
||||
VITE_EXTERNAL_PROD_API_URL: z.string().optional(),
|
||||
VITE_EXTERNAL_DEV_API_URL: z.string().optional(),
|
||||
VITE_EXTERNAL_API_URL: z.string().optional(),
|
||||
VITE_WEB_PROD_URL: z.string().optional(),
|
||||
VITE_WEB_DEV_URL: z.string().optional(),
|
||||
},
|
||||
|
||||
emptyStringAsUndefined: true,
|
||||
runtimeEnv: getRuntimeEnv() as any,
|
||||
|
||||
skipValidation: "process" in globalThis ? process.env.VITEST === "true" : false,
|
||||
})
|
||||
|
||||
function metaEnvIsEmpty() {
|
||||
try {
|
||||
return Object.keys(import.meta.env || {}).length === 0
|
||||
} catch {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
function getRuntimeEnv() {
|
||||
try {
|
||||
if (metaEnvIsEmpty()) {
|
||||
return process.env
|
||||
}
|
||||
return injectExternalEnv(import.meta.env)
|
||||
} catch {
|
||||
return process.env
|
||||
}
|
||||
}
|
||||
|
||||
declare const globalThis: any
|
||||
function injectExternalEnv<T>(originEnv: T): T {
|
||||
if (!("document" in globalThis)) {
|
||||
return originEnv
|
||||
}
|
||||
const prefix = "__followEnv"
|
||||
const env = globalThis[prefix]
|
||||
if (!env) {
|
||||
return originEnv
|
||||
}
|
||||
|
||||
for (const key in env) {
|
||||
originEnv[key as keyof T] = env[key]
|
||||
}
|
||||
return originEnv
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { env } from "@follow/shared/env"
|
||||
import { env } from "./constants/env"
|
||||
|
||||
export const IMAGE_PROXY_URL = "https://webp.follow.is"
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ export const selfRefererMatches = [env.VITE_OPENPANEL_API_URL, IMAGE_PROXY_URL].
|
|||
|
||||
export const imageRefererMatches = [
|
||||
{
|
||||
url: /^https:\/\/\w+\.sinaimg.cn/,
|
||||
url: /^https:\/\/\w+\.sinaimg\.cn/,
|
||||
referer: "https://weibo.com",
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue