Skip to content

Commit 47656e1

Browse files
jhildenbiddlesy-records
authored andcommitted
Fix for Vercal “unsupported modules” error
1 parent f0b47ec commit 47656e1

File tree

3 files changed

+27
-48
lines changed

3 files changed

+27
-48
lines changed

middleware.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1-
import rewriteRules from './rewriterules.config.js';
2-
31
// Exports
42
// =============================================================================
53
export const config = {
64
matcher: ['/preview/(index.html)?'],
75
};
86

7+
// Rewrite rules shared with local server configurations
8+
export const rewriteRules = [
9+
// Replace CDN URLs with local paths
10+
{
11+
match: /https?.*\/CHANGELOG.md/g,
12+
replace: '/CHANGELOG.md',
13+
},
14+
{
15+
// CDN versioned default
16+
// Ex1: //cdn.com/package-name
17+
// Ex2: http://cdn.com/[email protected]
18+
// Ex3: https://cdn.com/package-name@latest
19+
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*(?=["'])/g,
20+
replace: '/lib/docsify.min.js',
21+
},
22+
{
23+
// CDN paths to local paths
24+
// Ex1: //cdn.com/package-name/path/file.js => /path/file.js
25+
// Ex2: http://cdn.com/[email protected]/dist/file.js => /dist/file.js
26+
// Ex3: https://cdn.com/package-name@latest/dist/file.js => /dist/file.js
27+
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*\/(?:lib\/)/g,
28+
replace: '/lib/',
29+
},
30+
];
31+
932
// Serve virtual /preview/index.html
1033
// Note: See vercel.json for preview routing configuration
1134
// 1. Fetch index.html from /docs/ directory

rewriterules.config.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

server.configs.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from 'node:path';
22
import * as url from 'node:url';
3+
import { rewriteRules } from './middleware.js';
34

45
const __filename = url.fileURLToPath(import.meta.url);
56
const __dirname = path.dirname(__filename);
@@ -22,29 +23,7 @@ const dev = {
2223
...prod,
2324
files: ['CHANGELOG.md', 'docs/**/*', 'lib/**/*'],
2425
port: 3000,
25-
rewriteRules: [
26-
// Replace CDN URLs with local paths
27-
{
28-
match: /https?.*\/CHANGELOG.md/g,
29-
replace: '/CHANGELOG.md',
30-
},
31-
{
32-
// CDN versioned default
33-
// Ex1: //cdn.com/package-name
34-
// Ex2: http://cdn.com/[email protected]
35-
// Ex3: https://cdn.com/package-name@latest
36-
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*(?=["'])/g,
37-
replace: '/lib/docsify.min.js',
38-
},
39-
{
40-
// CDN paths to local paths
41-
// Ex1: //cdn.com/package-name/path/file.js => /path/file.js
42-
// Ex2: http://cdn.com/[email protected]/dist/file.js => /dist/file.js
43-
// Ex3: https://cdn.com/package-name@latest/dist/file.js => /dist/file.js
44-
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*\/(?:lib\/)/g,
45-
replace: '/lib/',
46-
},
47-
],
26+
rewriteRules,
4827
server: {
4928
...prod.server,
5029
routes: {

0 commit comments

Comments
 (0)