-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] minify task: Use workerpool for terser
Based on #700 * Changed logging to verbose * Added option 'useWorkers' to processor. Implicit activation through taskUtil parameter seemed a bit odd. Moved that to the minify task * Added JSDoc
- Loading branch information
1 parent
f9e6f2c
commit fd5c77f
Showing
6 changed files
with
167 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import workerpool from "workerpool"; | ||
import {minify} from "terser"; | ||
|
||
/** | ||
* @private | ||
* @module @ui5/builder/tasks/minifyWorker | ||
*/ | ||
|
||
/** | ||
* Preserve comments which contain: | ||
* <ul> | ||
* <li>copyright notice</li> | ||
* <li>license terms</li> | ||
* <li>"@ui5-bundle"</li> | ||
* <li>"@ui5-bundle-raw-include"</li> | ||
* </ul> | ||
* | ||
* @type {RegExp} | ||
*/ | ||
const copyrightCommentsAndBundleCommentPattern = /copyright|\(c\)(?:[0-9]+|\s+[0-9A-Za-z])|released under|license|\u00a9|^@ui5-bundle-raw-include |^@ui5-bundle /i; | ||
|
||
/** | ||
* Task to minify resources. | ||
* | ||
* @private | ||
* @function default | ||
* @static | ||
* | ||
* @param {object} parameters Parameters | ||
* @param {string} parameters.filename | ||
* @param {string} parameters.dbgFilename | ||
* @param {string} parameters.code | ||
* @param {object} parameters.sourceMapOptions | ||
* @returns {Promise<undefined>} Promise resolving once minification of the resource has finished | ||
*/ | ||
export default async function execMinification({ | ||
filename, | ||
dbgFilename, | ||
code, | ||
sourceMapOptions | ||
}) { | ||
try { | ||
return await minify({ | ||
// Use debug-name since this will be referenced in the source map "sources" | ||
[dbgFilename]: code | ||
}, { | ||
output: { | ||
comments: copyrightCommentsAndBundleCommentPattern, | ||
wrap_func_args: false | ||
}, | ||
compress: false, | ||
mangle: { | ||
reserved: [ | ||
"jQuery", | ||
"jquery", | ||
"sap", | ||
] | ||
}, | ||
sourceMap: sourceMapOptions | ||
}); | ||
} catch (err) { | ||
// Note: err.filename contains the debug-name | ||
throw new Error( | ||
`Minification failed with error: ${err.message} in file ${filename} ` + | ||
`(line ${err.line}, col ${err.col}, pos ${err.pos})`); | ||
} | ||
} | ||
|
||
if (!workerpool.isMainThread) { | ||
// Script got loaded through workerpool | ||
// => Create a worker and register public functions | ||
workerpool.worker({ | ||
execMinification | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters