Skip to content

Commit 479d28b

Browse files
authoredAug 20, 2020
refactor: code (#303)
1 parent 9d861d8 commit 479d28b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
 

‎src/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import path from 'path';
22
import os from 'os';
33

44
import { SourceMapConsumer } from 'source-map';
5-
import webpackSources from 'webpack-sources';
65
import webpack, {
76
util,
87
ModuleFilenameHelpers,
@@ -23,7 +22,9 @@ import schema from './options.json';
2322
import { minify as minifyFn } from './minify';
2423

2524
// webpack 5 exposes the sources property to ensure the right version of webpack-sources is used
26-
const sources = webpack.sources || webpackSources;
25+
const { SourceMapSource, RawSource, ConcatSource } =
26+
// eslint-disable-next-line global-require
27+
webpack.sources || require('webpack-sources');
2728

2829
class TerserPlugin {
2930
constructor(options = {}) {
@@ -267,7 +268,7 @@ class TerserPlugin {
267268
}
268269

269270
if (map) {
270-
outputSource = new sources.SourceMapSource(
271+
outputSource = new SourceMapSource(
271272
code,
272273
name,
273274
map,
@@ -276,7 +277,7 @@ class TerserPlugin {
276277
true
277278
);
278279
} else {
279-
outputSource = new sources.RawSource(code);
280+
outputSource = new RawSource(code);
280281
}
281282

282283
const assetInfo = { ...info, minimized: true };
@@ -300,7 +301,7 @@ class TerserPlugin {
300301
}
301302

302303
if (banner) {
303-
outputSource = new sources.ConcatSource(
304+
outputSource = new ConcatSource(
304305
shebang ? `${shebang}\n` : '',
305306
`/*! ${banner} */\n`,
306307
outputSource
@@ -580,7 +581,7 @@ class TerserPlugin {
580581
TerserPlugin.emitAsset(
581582
compilation,
582583
commentsFilename,
583-
new sources.RawSource(`${extractedComments}\n`)
584+
new RawSource(`${extractedComments}\n`)
584585
);
585586
});
586587

0 commit comments

Comments
 (0)
Please sign in to comment.