[FEATURE] Generate source maps for bundles#695
Conversation
863a79d to
7303498
Compare
4930295 to
7b51d11
Compare
e74779f to
9bb1025
Compare
BREAKING CHANGE: moduleBundler now returns an object containing a bundle- and an optional source map resource.
The bundle should still use predefine
Update scenarios in generateBundle.js
* Add option 'omitSourceMapResources' to minify task to control whether source map resource is tagged and no sourceMappingURL is added to the end of the resource content
ae415dc to
c13ce14
Compare
| * @typedef {object} ModuleBundleOptions | ||
| * @property {boolean} [optimize=true] Whether the module bundle gets minified | ||
| * @property {boolean} [sourceMap] Whether to generate a source map file for the bundle. | ||
| * Defaults to true if <code>optimize</code> is set to true |
There was a problem hiding this comment.
This is not correct anymore. A sourcemap is always created unless sourceMap: false is set.
In addition: Is this something to be added to the project configuration schema?
There was a problem hiding this comment.
I've added a bullet-point for adding 'sourceMap' to the specVersion 3.0 bundleOptions to UI5/cli#506
There was a problem hiding this comment.
As discussed, adding this to the bundleOptions makes sense
| * @param {ModuleBundleDefinition} parameters.options.bundleDefinition Module bundle definition | ||
| * @param {ModuleBundleOptions} [parameters.options.bundleOptions] Module bundle options | ||
| * @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with module bundle resources | ||
| * @returns {Promise<module:@ui5/builder.processors.MinifierResult[]>} Promise resolving with module bundle resources |
| * @alias module:@ui5/builder.processors.minifier | ||
| * @param {object} parameters Parameters | ||
| * @param {module:@ui5/fs.Resource[]} parameters.resources List of resources to be processed | ||
| * @param {boolean} [parameters.addSourceMappingUrl=true] |
There was a problem hiding this comment.
Usually in our processors we have an options object that contains such parameters.
There was a problem hiding this comment.
Yes, I forgot about that. This should be changed then 👍
| .then((processedResources) => { | ||
| return Promise.all(processedResources.map((resource) => { | ||
| .then((results) => { | ||
| const bundles = Array.prototype.concat.apply([], results); |
There was a problem hiding this comment.
I wonder why this is needed in here
| // For "unoptimized" bundles, the non-debug files have already been filtered out above. | ||
| // Now we need to create a mapping from the debug-variant resource path to the respective module name, | ||
| // which is basically the non-debug resource path, minus the "/resources/"" prefix. | ||
| // This mapping overwrites internal logic of the LocatorResourcePool which would otherwise determine | ||
| // the module name from the resource path, which would contain "-dbg" in this case. That would be | ||
| // incorrect since debug-variants should still keep the original module name. | ||
| for (let i = unoptimizedResources.length - 1; i >= 0; i--) { | ||
| const resourcePath = unoptimizedResources[i].getPath(); | ||
| if (taskUtil.getTag(resourcePath, taskUtil.STANDARD_TAGS.IsDebugVariant)) { | ||
| const nonDbgPath = ModuleName.getNonDebugName(resourcePath); | ||
| if (!nonDbgPath) { | ||
| throw new Error(`Failed to resolve non-debug name for ${resourcePath}`); | ||
| } | ||
| unoptimizedModuleNameMapping[resourcePath] = nonDbgPath.slice("/resources/".length); | ||
| } | ||
| } |
There was a problem hiding this comment.
We have this code in three places now, so it would be better to refactor it
There was a problem hiding this comment.
As discussed, maybe we could have all bundling tasks call the generateBundle-task or create a "helper" module in lib/tasks/bundlers/ for this purpose 👍
Issue was introduced with #695.
) Resolves #472 Supersedes SAP/ui5-builder#282 Based on #583 JIRA: CPOUI5FOUNDATION-434 Co-authored-by: Matthias Osswald <mat.osswald@sap.com>
SAP/ui5-builder#719) Issue was introduced with SAP/ui5-builder#695.
Supersedes #282
Based on UI5/cli#583
JIRA: CPOUI5FOUNDATION-434