Skip to content

Commit ca8afa5

Browse files
authored
fix: use CommonJS import for webpack-sources (#314)
webpack-sources is a CommonJS module and requires default import syntax in ESM. This fixes the package import to work with Node's ESM loader. Fixes #313
1 parent 25f0983 commit ca8afa5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/hooks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import { SyncWaterfallHook } from 'tapable';
55
import type { Compiler, Module, Compilation, LoaderContext } from 'webpack';
66
// Note: This was the old delcaration. It appears to be Webpack v3 compat.
77
// const { RawSource } = (webpack as any).sources || require('webpack-sources');
8-
import { RawSource } from 'webpack-sources';
8+
import webpackSources from 'webpack-sources';
99

1010
import type { EmitCountMap, InternalOptions } from './index.js';
1111

1212
import type { CompilationAsset, FileDescriptor } from './helpers.js';
1313
import { generateManifest, reduceAssets, reduceChunk, transformFiles } from './helpers.js';
1414

15+
const { RawSource } = webpackSources;
16+
1517
interface BeforeRunHookArgs {
1618
emitCountMap: EmitCountMap;
1719
manifestFileName: string;

test/integration/usage.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { execSync } from 'node:child_process';
2+
3+
import test from '../helpers/ava-compat';
4+
5+
// make implicit dependency explicit:
6+
import '../../src/index';
7+
8+
test.before(() => execSync('pnpm build'));
9+
10+
test('can be used as documented', (t) => {
11+
const readmeCode = "import { WebpackManifestPlugin } from 'webpack-manifest-plugin'";
12+
13+
t.deepEqual(execSync(`node -e "${readmeCode}"`, { encoding: 'utf-8' }), '');
14+
});

0 commit comments

Comments
 (0)