From 667e05144c2b5e763313b11f6c8b77c03067e3cd Mon Sep 17 00:00:00 2001 From: abdipramana Date: Thu, 26 Feb 2026 12:03:36 +0800 Subject: [PATCH] refactor buildFrontend and Webpack config to improve remote storage handling and access URL management and ensure proper checks for storage endpoints and streamline asset path configuration --- src/cli-methods.ts | 22 +++++++++++++++------- src/config-webpack-app.ts | 12 +++++++++--- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/cli-methods.ts b/src/cli-methods.ts index 4495e40..5e53d80 100644 --- a/src/cli-methods.ts +++ b/src/cli-methods.ts @@ -1863,13 +1863,17 @@ export const buildFrontend = async () => { }); }).then(async () => { // make sure environment is not development for storage config - // and if we want to upload to storage, we need set S3_BUCKET_ENDPOINT + // and ensure remote storage config exists for publish + const hasRemoteStorageEndpoint = + process.env.STATIC_S3_BUCKET_ENDPOINT || + process.env.UPLOADS_S3_BUCKET_ENDPOINT || + process.env.S3_BUCKET_ENDPOINT; if ( process.env.NODE_ENV === 'development' || - !process.env.S3_BUCKET_ENDPOINT + !hasRemoteStorageEndpoint ) { console.warn( - 'Upload build to storage skip in development environment or S3_BUCKET_ENDPOINT is not set', + 'Upload build to storage skipped in development environment or no S3 endpoint is configured', ); return; // process.exit(); @@ -1886,9 +1890,12 @@ export const buildFrontend = async () => { path.join(process.cwd(), 'scripts', 'storage-config.js') ); - // check if LincdFileStorage has a default FileStore - // if yes: copy all the files in the build folder over with LincdFileStorage - if (LinkedFileStorage.getDefaultStore()) { + const publishStore = + storageConfig.staticFileStore || LinkedFileStorage.getDefaultStore(); + + // check if we have a publish store + // if yes: copy all the files in the build folder over with that store + if (publishStore) { // get public directory const rootDirectory = 'public'; const pathDir = path.join(process.cwd(), rootDirectory); @@ -1921,7 +1928,8 @@ export const buildFrontend = async () => { const pathname = filePath.replace(pathDir, `/${rootDirectory}`); // upload file to storage - await LinkedFileStorage.saveFile(pathname, fileContent) + await publishStore + .saveFile(pathname, fileContent) .then(() => { clearSpinner.text = `${counter++}/${files.length}: - Published ${pathname} `; }) diff --git a/src/config-webpack-app.ts b/src/config-webpack-app.ts index aeb6671..5f88a6c 100644 --- a/src/config-webpack-app.ts +++ b/src/config-webpack-app.ts @@ -160,6 +160,11 @@ export const getWebpackAppConfig = async () => { // set up the storage config for the app await import(path.join(process.cwd(), 'scripts', 'storage-config.js')); const accessURL = LinkedFileStorage.accessURL; + const staticAccessURL = ( + process.env.STATIC_ACCESS_URL || + accessURL || + '' + ).replace(/\/$/, ''); // set up the public path for the app // for Capacitor apps (APP_ENV is set), use /bundles/ since Capacitor's webDir strips /public (see: capacitor.config.ts) @@ -171,8 +176,9 @@ export const getWebpackAppConfig = async () => { // ASSET_PATH is used load the assets from the correct path // if ASSET_PATH is set in environment (app builds), use it directly // otherwise, use CDN URL + bundlesPath for production, or bundlesPath for development - const ASSET_PATH = process.env.ASSET_PATH || - (accessURL ? accessURL + bundlesPath : bundlesPath); + const ASSET_PATH = + process.env.ASSET_PATH || + (staticAccessURL ? staticAccessURL + bundlesPath : bundlesPath); let config = await getLincdConfig(); @@ -241,7 +247,7 @@ export const getWebpackAppConfig = async () => { return cleanedUrl; } - const baseUrl = (accessURL || '').replace(/\/$/, ''); + const baseUrl = staticAccessURL; return `${baseUrl}${publicPath}${cleanedUrl}`; }, }),