Skip to content

Commit

Permalink
refactor: code (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Aug 20, 2020
1 parent 9d861d8 commit 479d28b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/index.js
Expand Up @@ -2,7 +2,6 @@ import path from 'path';
import os from 'os';

import { SourceMapConsumer } from 'source-map';
import webpackSources from 'webpack-sources';
import webpack, {
util,
ModuleFilenameHelpers,
Expand All @@ -23,7 +22,9 @@ import schema from './options.json';
import { minify as minifyFn } from './minify';

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

class TerserPlugin {
constructor(options = {}) {
Expand Down Expand Up @@ -267,7 +268,7 @@ class TerserPlugin {
}

if (map) {
outputSource = new sources.SourceMapSource(
outputSource = new SourceMapSource(
code,
name,
map,
Expand All @@ -276,7 +277,7 @@ class TerserPlugin {
true
);
} else {
outputSource = new sources.RawSource(code);
outputSource = new RawSource(code);
}

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

if (banner) {
outputSource = new sources.ConcatSource(
outputSource = new ConcatSource(
shebang ? `${shebang}\n` : '',
`/*! ${banner} */\n`,
outputSource
Expand Down Expand Up @@ -580,7 +581,7 @@ class TerserPlugin {
TerserPlugin.emitAsset(
compilation,
commentsFilename,
new sources.RawSource(`${extractedComments}\n`)
new RawSource(`${extractedComments}\n`)
);
});

Expand Down

0 comments on commit 479d28b

Please sign in to comment.