Skip to content

Commit

Permalink
[fix] externalize middlewares.js when using adapter-node's entryPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Conduitry committed Sep 23, 2021
1 parent 4c47afb commit 60ca1b7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/adapter-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
statSync,
writeFileSync
} from 'fs';
import { join } from 'path';
import { join, resolve } from 'path';
import { pipeline } from 'stream';
import glob from 'tiny-glob';
import { fileURLToPath } from 'url';
Expand Down Expand Up @@ -81,7 +81,6 @@ export default function ({
entryPoints: [entryPoint],
outfile: join(out, 'index.js'),
bundle: true,
external: ['./middlewares.js'], // does not work, eslint does not exclude middlewares from target
format: 'esm',
platform: 'node',
target: 'node12',
Expand All @@ -90,8 +89,12 @@ export default function ({
{
name: 'fix-middlewares-exclude',
setup(build) {
// Match an import called "./middlewares.js" and mark it as external
build.onResolve({ filter: /^\.\/middlewares\.js$/ }, () => ({ external: true }));
// Match an import of "middlewares.js" and mark it as external
build.onResolve({ filter: /\/middlewares\.js$/ }, ({ path, resolveDir }) => {
if (resolve(resolveDir, path) === resolve(out, 'middlewares.js')) {
return { path: './middlewares.js', external: true };
}
});
}
}
]
Expand Down

0 comments on commit 60ca1b7

Please sign in to comment.