Skip to content

Commit

Permalink
Fix for Vercal “unsupported modules” error
Browse files Browse the repository at this point in the history
  • Loading branch information
jhildenbiddle committed Dec 21, 2023
1 parent 4b30eb6 commit 82fefbd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 48 deletions.
27 changes: 25 additions & 2 deletions middleware.js
@@ -1,11 +1,34 @@
import rewriteRules from './rewriterules.config.js';

// Exports
// =============================================================================
export const config = {
matcher: ['/preview/(index.html)?'],
};

// Rewrite rules shared with local server configurations
export const rewriteRules = [
// Replace CDN URLs with local paths
{
match: /https?.*\/CHANGELOG.md/g,
replace: '/CHANGELOG.md',
},
{
// CDN versioned default
// Ex1: //cdn.com/package-name
// Ex2: http://cdn.com/package-name@1.0.0
// Ex3: https://cdn.com/package-name@latest
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*(?=["'])/g,
replace: '/lib/docsify.min.js',
},
{
// CDN paths to local paths
// Ex1: //cdn.com/package-name/path/file.js => /path/file.js
// Ex2: http://cdn.com/package-name@1.0.0/dist/file.js => /dist/file.js
// Ex3: https://cdn.com/package-name@latest/dist/file.js => /dist/file.js
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*\/(?:lib\/)/g,
replace: '/lib/',
},
];

// Serve virtual /preview/index.html
// Note: See vercel.json for preview routing configuration
// 1. Fetch index.html from /docs/ directory
Expand Down
23 changes: 0 additions & 23 deletions rewriterules.config.js

This file was deleted.

25 changes: 2 additions & 23 deletions server.configs.js
@@ -1,5 +1,6 @@
import * as path from 'node:path';
import * as url from 'node:url';
import { rewriteRules } from './middleware.js';

const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand All @@ -22,29 +23,7 @@ const dev = {
...prod,
files: ['CHANGELOG.md', 'docs/**/*', 'lib/**/*'],
port: 3000,
rewriteRules: [
// Replace CDN URLs with local paths
{
match: /https?.*\/CHANGELOG.md/g,
replace: '/CHANGELOG.md',
},
{
// CDN versioned default
// Ex1: //cdn.com/package-name
// Ex2: http://cdn.com/package-name@1.0.0
// Ex3: https://cdn.com/package-name@latest
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*(?=["'])/g,
replace: '/lib/docsify.min.js',
},
{
// CDN paths to local paths
// Ex1: //cdn.com/package-name/path/file.js => /path/file.js
// Ex2: http://cdn.com/package-name@1.0.0/dist/file.js => /dist/file.js
// Ex3: https://cdn.com/package-name@latest/dist/file.js => /dist/file.js
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*\/(?:lib\/)/g,
replace: '/lib/',
},
],
rewriteRules,
server: {
...prod.server,
routes: {
Expand Down

0 comments on commit 82fefbd

Please sign in to comment.