Skip to content

Commit

Permalink
fix: only import webpack types (#297)
Browse files Browse the repository at this point in the history
* remove webpack import

* chore: rename _loaderContext

---------

Co-authored-by: Andrew Powell <shellscape@users.noreply.github.com>
Co-authored-by: shellscape <andrew@shellscape.org>
  • Loading branch information
3 people committed Jun 19, 2023
1 parent 9a39d31 commit 64faade
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ interface LegacyModule extends Module {
userRequest?: any;
}


const normalModuleLoaderHook = (
{ moduleAssets }: { moduleAssets: Record<any, any> },
loaderContext: LoaderContext<any>,
context: unknown,
module: LegacyModule
) => {
const loaderContext = context as LoaderContext<any>;
const { emitFile } = loaderContext;

// eslint-disable-next-line no-param-reassign
loaderContext.emitFile = (file: string, content: string, sourceMap: any) => {
if (module.userRequest && !moduleAssets[file]) {
Object.assign(moduleAssets, { [file]: join(dirname(file), basename(module.userRequest)) });
Expand Down
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { relative, resolve } from 'path';

import { SyncHook } from 'tapable';
import { Compiler, WebpackPluginInstance, Compilation } from 'webpack';
// @ts-ignore
import NormalModule from 'webpack/lib/NormalModule';

import type { Compiler, WebpackPluginInstance, Compilation } from 'webpack';
import { FileDescriptor } from './helpers';
import { beforeRunHook, emitHook, getCompilerHooks, normalModuleLoaderHook } from './hooks';

Expand Down Expand Up @@ -71,6 +68,7 @@ class WebpackManifestPlugin implements WebpackPluginInstance {
}

apply(compiler: Compiler) {
const { NormalModule } = compiler.webpack;
const moduleAssets = {};
const manifestFileName = resolve(compiler.options.output?.path || './', this.options.fileName);
const manifestAssetId = relative(compiler.options.output?.path || './', manifestFileName);
Expand Down

0 comments on commit 64faade

Please sign in to comment.