| | |
| | | const schema = require("./options.json"); |
| | | const { |
| | | esbuildMinify, |
| | | jsonMinify, |
| | | memoize, |
| | | swcMinify, |
| | | terserMinify, |
| | |
| | | /** @typedef {import("webpack").Configuration} Configuration */ |
| | | /** @typedef {import("webpack").Asset} Asset */ |
| | | /** @typedef {import("webpack").AssetInfo} AssetInfo */ |
| | | /** @typedef {import("webpack").TemplatePath} TemplatePath */ |
| | | /** @typedef {import("jest-worker").Worker} JestWorker */ |
| | | /** @typedef {import("@jridgewell/trace-mapping").EncodedSourceMap & { sources: string[], sourcesContent?: string[], file: string }} RawSourceMap */ |
| | | /** @typedef {import("@jridgewell/trace-mapping").TraceMap} TraceMap */ |
| | |
| | | /** @typedef {RegExp | string} Rule */ |
| | | /** @typedef {Rule[] | Rule} Rules */ |
| | | |
| | | // eslint-disable-next-line jsdoc/no-restricted-syntax |
| | | // eslint-disable-next-line jsdoc/reject-any-type |
| | | /** @typedef {any} EXPECTED_ANY */ |
| | | |
| | | /** |
| | | * @callback ExtractCommentsFunction |
| | | * @param {any} astNode ast Node |
| | | * @param {{ value: string, type: 'comment1' | 'comment2' | 'comment3' | 'comment4', pos: number, line: number, col: number }} comment comment node |
| | | * @param {EXPECTED_ANY} astNode ast Node |
| | | * @param {{ value: string, type: "comment1" | "comment2" | "comment3" | "comment4", pos: number, line: number, col: number }} comment comment node |
| | | * @returns {boolean} true when need to extract comment, otherwise false |
| | | */ |
| | | |
| | | /** |
| | | * @typedef {boolean | 'all' | 'some' | RegExp | ExtractCommentsFunction} ExtractCommentsCondition |
| | | * @typedef {boolean | "all" | "some" | RegExp | ExtractCommentsFunction} ExtractCommentsCondition |
| | | */ |
| | | |
| | | // eslint-disable-next-line jsdoc/no-restricted-syntax |
| | | /** |
| | | * @typedef {string | ((fileData: any) => string)} ExtractCommentsFilename |
| | | * @typedef {TemplatePath} ExtractCommentsFilename |
| | | */ |
| | | |
| | | /** |
| | |
| | | * @typedef {object} MinimizedResult |
| | | * @property {string=} code code |
| | | * @property {RawSourceMap=} map source map |
| | | * @property {Array<Error | string>=} errors errors |
| | | * @property {Array<Error | string>=} warnings warnings |
| | | * @property {Array<string>=} extractedComments extracted comments |
| | | * @property {(Error | string)[]=} errors errors |
| | | * @property {(Error | string)[]=} warnings warnings |
| | | * @property {string[]=} extractedComments extracted comments |
| | | */ |
| | | |
| | | /** |
| | | * @typedef {{ [file: string]: string }} Input |
| | | */ |
| | | |
| | | // eslint-disable-next-line jsdoc/no-restricted-syntax |
| | | /** |
| | | * @typedef {{ [key: string]: any }} CustomOptions |
| | | * @typedef {{ [key: string]: EXPECTED_ANY }} CustomOptions |
| | | */ |
| | | |
| | | /** |
| | |
| | | * @typedef {object} MinimizeFunctionHelpers |
| | | * @property {() => string | undefined=} getMinimizerVersion function that returns version of minimizer |
| | | * @property {() => boolean | undefined=} supportsWorkerThreads true when minimizer support worker threads, otherwise false |
| | | * @property {() => boolean | undefined=} supportsWorker true when minimizer support worker, otherwise false |
| | | */ |
| | | |
| | | /** |
| | |
| | | */ |
| | | |
| | | const getTraceMapping = memoize(() => require("@jridgewell/trace-mapping")); |
| | | const getSerializeJavascript = memoize(() => require("serialize-javascript")); |
| | | const getSerializeJavascript = memoize(() => require("./serialize-javascript")); |
| | | |
| | | /** |
| | | * @template [T=import("terser").MinifyOptions] |
| | |
| | | baseDataPath: "options" |
| | | }); |
| | | |
| | | // TODO handle json and etc in the next major release |
| | | // TODO make `minimizer` option instead `minify` and `terserOptions` in the next major release, also rename `terserMinify` to `terserMinimize` |
| | | const { |
| | | minify = ( /** @type {MinimizerImplementation<T>} */terserMinify), |
| | |
| | | let initializedWorker; |
| | | /** @type {undefined | number} */ |
| | | let numberOfWorkers; |
| | | if (optimizeOptions.availableNumberOfCores > 0) { |
| | | const needCreateWorker = optimizeOptions.availableNumberOfCores > 0 && (typeof this.options.minimizer.implementation.supportsWorker === "undefined" || typeof this.options.minimizer.implementation.supportsWorker === "function" && this.options.minimizer.implementation.supportsWorker()); |
| | | if (needCreateWorker) { |
| | | // Do not create unnecessary workers when the number of files is less than the available cores, it saves memory |
| | | numberOfWorkers = Math.min(numberOfAssets, optimizeOptions.availableNumberOfCores); |
| | | getWorker = () => { |
| | |
| | | TerserPlugin.uglifyJsMinify = uglifyJsMinify; |
| | | TerserPlugin.swcMinify = swcMinify; |
| | | TerserPlugin.esbuildMinify = esbuildMinify; |
| | | TerserPlugin.jsonMinify = jsonMinify; |
| | | module.exports = TerserPlugin; |