Skip to content

Commit

Permalink
fix: use older webpack-sources for WP4 and built-in one for WP5 (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored Jan 13, 2023
1 parent 6fe85b4 commit 106484b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"json5": "^2.2.0",
"loader-utils": "^2.0.0",
"tapable": "^2.2.0",
"webpack-sources": "^2.2.0"
"webpack-sources": "^1.4.3"
},
"devDependencies": {
"@pvtnbr/eslint-config": "^0.33.0",
"@types/loader-utils": "^2.0.3",
"@types/node": "^18.11.18",
"@types/webpack": "^4.41.33",
"@types/webpack-sources": "^3.2.0",
"@types/webpack-sources": "^0.1.9",
"css-loader": "^5.2.7",
"eslint": "^8.31.0",
"manten": "^0.6.0",
Expand Down
25 changes: 12 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions src/minify-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { transform as defaultEsbuildTransform } from 'esbuild';
import { RawSource, SourceMapSource } from 'webpack-sources';
import {
RawSource as WP4RawSource,
SourceMapSource as WP4SourceMapSource,
} from 'webpack-sources';
import webpack from 'webpack';
import type {
SyncHook, SyncBailHook, AsyncSeriesHook, HookMap,
Expand Down Expand Up @@ -107,7 +110,13 @@ class ESBuildMinifyPlugin {
private async transformAssets(
compilation: Compilation,
): Promise<void> {
const { options: { devtool } } = compilation.compiler;
const { compiler } = compilation;
const { options: { devtool } } = compiler;

// @ts-expect-error Only exists on Webpack 5
const sources = compiler.webpack?.sources;
const SourceMapSource = (sources ? sources.SourceMapSource : WP4SourceMapSource);
const RawSource = (sources ? sources.RawSource : WP4RawSource);

const sourcemap = (
// TODO: drop support for esbuild sourcemap in future so it all goes through WP API
Expand Down

0 comments on commit 106484b

Please sign in to comment.