Remove cacheKeys option and improve filtering (#6559)
More cleanup of terser-plugin.
This commit is contained in:
parent
51fc26161d
commit
9b62f208bb
4 changed files with 16 additions and 43 deletions
|
@ -67,13 +67,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, isServe
|
|||
const terserPluginConfig = {
|
||||
parallel: true,
|
||||
sourceMap: false,
|
||||
cache: true,
|
||||
cacheKeys: (keys: any) => {
|
||||
// path changes per build because we add buildId
|
||||
// because the input is already hashed the path is not needed
|
||||
delete keys.path
|
||||
return keys
|
||||
}
|
||||
cache: true
|
||||
}
|
||||
|
||||
let webpackConfig: webpack.Configuration = {
|
||||
|
|
|
@ -2,42 +2,32 @@
|
|||
no-param-reassign
|
||||
*/
|
||||
import crypto from 'crypto';
|
||||
import path from 'path';
|
||||
|
||||
import { SourceMapConsumer } from 'source-map';
|
||||
import { SourceMapSource, RawSource, ConcatSource } from 'webpack-sources';
|
||||
import { SourceMapSource, RawSource } from 'webpack-sources';
|
||||
import RequestShortener from 'webpack/lib/RequestShortener';
|
||||
import ModuleFilenameHelpers from 'webpack/lib/ModuleFilenameHelpers';
|
||||
import serialize from 'serialize-javascript';
|
||||
import terserPackageJson from 'terser/package.json';
|
||||
import TaskRunner from './TaskRunner';
|
||||
|
||||
const warningRegex = /\[.+:([0-9]+),([0-9]+)\]/;
|
||||
|
||||
const JS_REGEX = /\.m?js$/
|
||||
|
||||
class TerserPlugin {
|
||||
constructor(options = {}) {
|
||||
const {
|
||||
minify,
|
||||
terserOptions = {},
|
||||
test = /\.m?js(\?.*)?$/i,
|
||||
warningsFilter = () => true,
|
||||
sourceMap = false,
|
||||
cache = false,
|
||||
cacheKeys = (defaultCacheKeys) => defaultCacheKeys,
|
||||
parallel = false,
|
||||
include,
|
||||
exclude,
|
||||
parallel = false
|
||||
} = options;
|
||||
|
||||
this.options = {
|
||||
test,
|
||||
warningsFilter,
|
||||
sourceMap,
|
||||
cache,
|
||||
cacheKeys,
|
||||
parallel,
|
||||
include,
|
||||
exclude,
|
||||
minify,
|
||||
terserOptions: {
|
||||
output: {
|
||||
|
@ -156,7 +146,7 @@ class TerserPlugin {
|
|||
Array.from(chunks)
|
||||
.reduce((acc, chunk) => acc.concat(chunk.files || []), [])
|
||||
.concat(compilation.additionalChunkAssets || [])
|
||||
.filter(ModuleFilenameHelpers.matchObject.bind(null, this.options))
|
||||
.filter((file) => JS_REGEX.test(file))
|
||||
.forEach((file) => {
|
||||
let inputSourceMap;
|
||||
|
||||
|
@ -197,8 +187,8 @@ class TerserPlugin {
|
|||
};
|
||||
|
||||
if (this.options.cache) {
|
||||
const defaultCacheKeys = {
|
||||
terser: terserPackageJson.version,
|
||||
task.cacheKeys = {
|
||||
terser: '3.16.1',
|
||||
// eslint-disable-next-line global-require
|
||||
'terser-webpack-plugin': '1.2.2',
|
||||
'terser-webpack-plugin-options': this.options,
|
||||
|
@ -206,9 +196,7 @@ class TerserPlugin {
|
|||
.createHash('md4')
|
||||
.update(input)
|
||||
.digest('hex'),
|
||||
};
|
||||
|
||||
task.cacheKeys = this.options.cacheKeys(defaultCacheKeys, file);
|
||||
}
|
||||
}
|
||||
|
||||
tasks.push(task);
|
||||
|
@ -232,9 +220,8 @@ class TerserPlugin {
|
|||
}
|
||||
|
||||
results.forEach((data, index) => {
|
||||
const { file, input, inputSourceMap, commentsFile } = tasks[index];
|
||||
const { file, input, inputSourceMap } = tasks[index];
|
||||
const { error, map, code, warnings } = data;
|
||||
let { extractedComments } = data;
|
||||
|
||||
let sourceMap = null;
|
||||
|
||||
|
@ -313,13 +300,10 @@ class TerserPlugin {
|
|||
// Regenerate `contenthash` for minified assets
|
||||
for (const template of [mainTemplate, chunkTemplate]) {
|
||||
template.hooks.hashForChunk.tap(plugin, (hash) => {
|
||||
const data = serialize({
|
||||
terser: terserPackageJson.version,
|
||||
terserOptions: this.options.terserOptions,
|
||||
});
|
||||
|
||||
hash.update('TerserPlugin');
|
||||
hash.update(data);
|
||||
// Terser version
|
||||
// Has to be updated when options change too
|
||||
hash.update('3.16.1');
|
||||
return hash
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
"react-is": "16.6.3",
|
||||
"recursive-copy": "2.0.6",
|
||||
"resolve": "1.5.0",
|
||||
"serialize-javascript": "1.4.0",
|
||||
"serialize-javascript": "1.6.1",
|
||||
"source-map": "0.6.1",
|
||||
"strip-ansi": "3.0.1",
|
||||
"styled-jsx": "3.2.1",
|
||||
|
|
|
@ -11040,12 +11040,7 @@ sentence-case@^2.1.0:
|
|||
no-case "^2.2.0"
|
||||
upper-case-first "^1.1.2"
|
||||
|
||||
serialize-javascript@1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.4.0.tgz#7c958514db6ac2443a8abc062dc9f7886a7f6005"
|
||||
integrity sha1-fJWFFNtqwkQ6irwGLcn3iGp/YAU=
|
||||
|
||||
serialize-javascript@^1.4.0:
|
||||
serialize-javascript@1.6.1, serialize-javascript@^1.4.0:
|
||||
version "1.6.1"
|
||||
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.6.1.tgz#4d1f697ec49429a847ca6f442a2a755126c4d879"
|
||||
integrity sha512-A5MOagrPFga4YaKQSWHryl7AXvbQkEqpw4NNYMTNYUNV51bA8ABHgYFpqKx+YFFrw59xMV1qGH1R4AgoNIVgCw==
|
||||
|
|
Loading…
Reference in a new issue