-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui5-tooling-modules): chunks are stored in module name folder (#922)
To simplify the handling of chunks of npm packages, they are now stored in a folder with the name of the module. With this option a single `resourceroots` mapping is sufficient to delegate all requests to the npm package and its chunks to the proper location. This is especially useful for CDN scenarios when the npm package is not included. Example: CDN usage + `jspdf` ```html <html> <head> [...] <script ... data-sap-ui-resourceroots='{ ... "jspdf": "resources/jspdf" }' ``` Using this `resourceroots` mapping, all requests to `jspdf` and its chunks are now resolved to `resources/jspdf*`. * `jspdf` => `resources/jspdf.js` * `jspdf/0c1H2u3N4k5` => `resources/jspdf/0c1H2u3N4k5.js` Fixes #915
- Loading branch information
1 parent
367a366
commit c2ad65d
Showing
5 changed files
with
74 additions
and
10 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
packages/ui5-tooling-modules/lib/rollup-plugin-polyfill-node-ignore.js
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,28 @@ | ||
/* eslint-disable no-unused-vars */ | ||
module.exports = function ({ log } = {}) { | ||
const isBuiltInModule = function (module) { | ||
try { | ||
if (!require("path").isAbsolute(module) && require.resolve(module) === module) { | ||
return true; | ||
} | ||
} catch (ex) { | ||
/* */ | ||
} | ||
return false; | ||
}; | ||
return { | ||
name: "polyfill-node-ignore", | ||
resolveId: function (source) { | ||
if (isBuiltInModule(source)) { | ||
return { id: `${source}?polyfill-node-ignore`, moduleSideEffects: false }; | ||
} | ||
return null; | ||
}, | ||
load: function (source) { | ||
if (source.endsWith("?polyfill-node-ignore")) { | ||
return ""; | ||
} | ||
return null; | ||
}, | ||
}; | ||
}; |
37 changes: 37 additions & 0 deletions
37
packages/ui5-tooling-modules/lib/rollup-plugin-polyfill-node-override.js
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,37 @@ | ||
/* eslint-disable no-unused-vars */ | ||
const nodePolyfills = require("rollup-plugin-polyfill-node"); | ||
module.exports = function ({ log } = {}) { | ||
const { resolveId } = nodePolyfills(); | ||
return { | ||
name: "polyfill-node-override", | ||
resolveId: function (importee, importer, options) { | ||
if (importee === "http2") { | ||
return { id: "http2?node-polyfill-override", moduleSideEffects: false }; | ||
} | ||
if (importee === "async_hooks") { | ||
return { id: "async_hooks?node-polyfill-override", moduleSideEffects: false }; | ||
} | ||
if (importee.startsWith("node:")) { | ||
return resolveId.call(this, importee.substr("node:".length), importer, options); | ||
} | ||
return null; | ||
}, | ||
load: function (source) { | ||
if (source === "http2?node-polyfill-override") { | ||
return `export const constants = { | ||
HTTP2_HEADER_AUTHORITY: "authority", | ||
HTTP2_HEADER_METHOD: "method", | ||
HTTP2_HEADER_PATH: "path", | ||
HTTP2_HEADER_SCHEME: "scheme", | ||
HTTP2_HEADER_CONTENT_LENGTH: "content-length", | ||
HTTP2_HEADER_EXPECT: "expect", | ||
HTTP2_HEADER_STATUS: "status" | ||
};`; | ||
} | ||
if (source === "async_hooks?node-polyfill-override") { | ||
return `export class AsyncResource {};`; | ||
} | ||
return null; | ||
}, | ||
}; | ||
}; |
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
4 changes: 2 additions & 2 deletions
4
...g-modules/test/__snap__/jspdf-ZSsH8-2i.js → ...g-modules/test/__snap__/jspdf/Ho2Fpw1t.js
Large diffs are not rendered by default.
Oops, something went wrong.