Skip to content

Commit

Permalink
fix: handle empty build (#357)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Pantic <[email protected]>
Co-authored-by: Hiroki Osame <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2024
1 parent 51685cd commit 3bddb9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ export default class EsbuildPlugin {
* Webpack 5: https://github.com/webpack/webpack/blob/v5.75.0/lib/SourceMapDevToolModuleOptionsPlugin.js#LL27
*/
let useSourceMap = false;

/**
* `finishModules` hook is called after all the `buildModule` hooks are called,
* which is where the `useSourceMap` flag is set
* https://webpack.js.org/api/compilation-hooks/#finishmodules
*/
compilation.hooks.finishModules.tap(
pluginName,
(modules) => {
Expand All @@ -209,7 +215,9 @@ export default class EsbuildPlugin {
? modules[0]
: (modules as Set<webpack5.Module>).values().next().value as webpack5.Module
);
useSourceMap = firstModule.useSourceMap;
if (firstModule) {
useSourceMap = firstModule.useSourceMap;
}
},
);

Expand Down
12 changes: 12 additions & 0 deletions tests/specs/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,5 +738,17 @@ export default testSuite(({ describe }, webpack: typeof webpack4 | typeof webpac
expect(exportedFunction('hello world')).toBe('hello world');
assertMinified(exportedFunction.toString());
});

// https://github.com/privatenumber/esbuild-loader/issues/356
test('can handle empty modules set', async () => {
await expect(build(
fixtures.blank,
(config) => {
config.entry = 'not-there.js';
configureEsbuildMinifyPlugin(config);
},
webpack,
)).resolves.toBeTruthy();
});
});
});

0 comments on commit 3bddb9d

Please sign in to comment.