Skip to content

Commit 9c8be4c

Browse files
committed
feat: Bumped Next.js to 12.
1 parent a371d0a commit 9c8be4c

File tree

6 files changed

+1442
-1858
lines changed

6 files changed

+1442
-1858
lines changed

build/utils/loader.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function uploadcareLoader({ src, width, quality }) {
1212
? (0, helpers_1.generateDefaultProxyEndpoint)(customProxyDomain)
1313
: null;
1414
const proxyEndpoint = customProxyEndpoint || (0, helpers_1.generateDefaultProxyEndpoint)(publicKey);
15-
const root = (0, helpers_1.trimTrailingSlash)(proxyEndpoint);
15+
const basePath = (0, helpers_1.trimTrailingSlash)(process.env.NEXT_PUBLIC_UPLOADCARE_APP_BASE_PATH || '');
16+
const proxy = (0, helpers_1.trimTrailingSlash)(proxyEndpoint);
1617
const isOnCdn = (0, helpers_1.isCdnUrl)(src, cdnDomain);
1718
if (!(0, helpers_1.isProduction)() && !isOnCdn) {
1819
const isPublicKeySet = !(0, helpers_1.isDotenvParamEmpty)(publicKey);
@@ -21,15 +22,22 @@ function uploadcareLoader({ src, width, quality }) {
2122
throw new Error(`Both NEXT_PUBLIC_UPLOADCARE_PUBLIC_KEY and NEXT_PUBLIC_UPLOADCARE_CUSTOM_PROXY_DOMAIN are not set. Please set either one.`);
2223
}
2324
if (src.startsWith('/')) {
24-
throw new Error(`Failed to parse "${src}" in "uploadcareLoader", Uploadcare loader doesn't support relative images.`);
25+
return src;
2526
}
2627
}
28+
// Process local images in Production.
29+
if ((0, helpers_1.isProduction)() && !isOnCdn && src.startsWith('/')) {
30+
const isBasePathSet = !(0, helpers_1.isDotenvParamEmpty)(basePath);
31+
if (!isBasePathSet) {
32+
return src;
33+
}
34+
return `${basePath}${src}`;
35+
}
2736
const filename = (0, helpers_1.getFilename)(src);
2837
const extension = (0, helpers_1.getExtension)(filename);
2938
// Some extensions are not processed by Uploadcare, e.g. SVG.
3039
if (constants_1.NOT_PROCESSED_EXTENSIONS.includes(extension)) {
31-
// @todo: Test non-CDN urls.
32-
return isOnCdn ? src : `${root}${src}`;
40+
return isOnCdn ? src : `${basePath}${src}`;
3341
}
3442
// Demo: https://ucarecdn.com/a6f8abc8-f92e-460a-b7a1-c5cd70a18cdb/-/format/auto/-/resize/300x/vercel.png
3543
const userParams = (0, helpers_1.parseUserParamsString)(userParamsString);
@@ -48,6 +56,6 @@ function uploadcareLoader({ src, width, quality }) {
4856
const withoutFilename = src.slice(0, src.lastIndexOf('/'));
4957
return `${withoutFilename}${apiParamsString}${filename}`;
5058
}
51-
return `${root}${apiParamsString}${src}`;
59+
return `${proxy}${apiParamsString}${src}`;
5260
}
5361
exports.uploadcareLoader = uploadcareLoader;

example/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uploadcare/nextjs-loader-demo",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",
@@ -9,15 +9,15 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"next": "11.1.2",
1312
"@uploadcare/nextjs-loader": "*",
14-
"react": "17.0.2",
15-
"react-dom": "17.0.2"
13+
"next": "^12.0.2",
14+
"react": "^17.0.2",
15+
"react-dom": "^17.0.2"
1616
},
1717
"devDependencies": {
18-
"@types/react": "17.0.27",
19-
"eslint": "7.32.0",
20-
"eslint-config-next": "11.1.2",
21-
"typescript": "4.4.3"
18+
"@types/react": "^17.0.27",
19+
"eslint": "^7.32.0",
20+
"eslint-config-next": "^11.1.2",
21+
"typescript": "^4.4.3"
2222
}
2323
}

example/tsconfig.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4-
"lib": ["dom", "dom.iterable", "esnext"],
4+
"lib": [
5+
"dom",
6+
"dom.iterable",
7+
"esnext"
8+
],
59
"allowJs": true,
610
"skipLibCheck": true,
711
"strict": true,
@@ -12,8 +16,15 @@
1216
"moduleResolution": "node",
1317
"resolveJsonModule": true,
1418
"isolatedModules": true,
15-
"jsx": "preserve"
19+
"jsx": "preserve",
20+
"incremental": true
1621
},
17-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
18-
"exclude": ["node_modules"]
22+
"include": [
23+
"next-env.d.ts",
24+
"**/*.ts",
25+
"**/*.tsx"
26+
],
27+
"exclude": [
28+
"node_modules"
29+
]
1930
}

0 commit comments

Comments
 (0)