Skip to content

Commit c7a769a

Browse files
committed
fix: eliminate code splitting to support Fastly runtime
Fastly's WASM runtime doesn't support importScripts which webpack uses for code splitting. Changes: - Convert dynamic adapter imports to static imports in edge-index.js - Add webpackIgnore comments to fastly:* module dynamic imports - Add splitChunks: false to webpack optimization 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Lars Trieloff <[email protected]>
1 parent 488ef19 commit c7a769a

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/EdgeBundler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export default class EdgeBundler extends WebpackBundler {
122122
concatenateModules: false,
123123
mangleExports: false,
124124
moduleIds: 'named',
125+
// Disable code splitting - Fastly runtime doesn't support importScripts
126+
splitChunks: false,
125127
},
126128
plugins: [],
127129
};

src/template/context-logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function createFastlyLogger(context) {
6363

6464
// Initialize Fastly logger module asynchronously
6565
// eslint-disable-next-line import/no-unresolved
66-
loggerPromise = import('fastly:logger').then((module) => {
66+
loggerPromise = import(/* webpackIgnore: true */ 'fastly:logger').then((module) => {
6767
loggerModule = module;
6868
loggersReady = true;
6969
loggerPromise = null;

src/template/edge-index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
*/
1212
/* eslint-env serviceworker */
1313

14+
// Static imports to avoid code splitting (Fastly runtime doesn't support importScripts)
15+
import { handleRequest as handleCloudflareRequest } from './cloudflare-adapter.js';
16+
import { handleRequest as handleFastlyRequest } from './fastly-adapter.js';
17+
1418
// Platform detection based on request properties and runtime-specific modules
1519
let detectedPlatform = null;
1620

@@ -29,7 +33,7 @@ async function detectPlatform(request) {
2933
// Try Fastly by checking for fastly:env module
3034
try {
3135
/* eslint-disable-next-line import/no-unresolved */
32-
await import('fastly:env');
36+
await import(/* webpackIgnore: true */ 'fastly:env');
3337
detectedPlatform = 'fastly';
3438
// eslint-disable-next-line no-console
3539
console.log('detected fastly environment');
@@ -45,13 +49,11 @@ async function getHandler(request) {
4549
const platform = await detectPlatform(request);
4650

4751
if (platform === 'cloudflare') {
48-
const { handleRequest } = await import('./cloudflare-adapter.js');
49-
return handleRequest;
52+
return handleCloudflareRequest;
5053
}
5154

5255
if (platform === 'fastly') {
53-
const { handleRequest } = await import('./fastly-adapter.js');
54-
return handleRequest;
56+
return handleFastlyRequest;
5557
}
5658

5759
return null;

src/template/fastly-runtime.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let loggerModule = null;
2626
export async function getFastlyEnv() {
2727
if (!envModule) {
2828
/* eslint-disable-next-line import/no-unresolved */
29-
envModule = await import('fastly:env');
29+
envModule = await import(/* webpackIgnore: true */ 'fastly:env');
3030
}
3131
return envModule;
3232
}
@@ -41,7 +41,7 @@ export async function getSecretStore() {
4141
}
4242
try {
4343
/* eslint-disable-next-line import/no-unresolved */
44-
secretStoreModule = await import('fastly:secret-store');
44+
secretStoreModule = await import(/* webpackIgnore: true */ 'fastly:secret-store');
4545
return secretStoreModule.SecretStore;
4646
} catch {
4747
return null;
@@ -58,7 +58,7 @@ export async function getLogger() {
5858
}
5959
try {
6060
/* eslint-disable-next-line import/no-unresolved */
61-
loggerModule = await import('fastly:logger');
61+
loggerModule = await import(/* webpackIgnore: true */ 'fastly:logger');
6262
return loggerModule.Logger;
6363
} catch {
6464
return null;

0 commit comments

Comments
 (0)