UNPKG

@communities-webruntime/services

Version:

If you would like to run Lightning Web Runtime without the CLI, we expose some of our programmatic APIs available in Node.js. If you're looking for the CLI documentation [you can find that here](https://www.npmjs.com/package/@communities-webruntime/cli).

49 lines 1.89 kB
"use strict"; /** @hidden */ /** * Copyright (c) 2019, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ Object.defineProperty(exports, "__esModule", { value: true }); const context_service_1 = require("../context/context-service"); const { getContext } = context_service_1.ContextService; const RESOURCE_URL_PREFIX = '@salesforce/resourceUrl/'; const CONTENT_ASSET_URL_PREFIX = '@salesforce/contentAssetUrl/'; /** * Check whether the given id is a @salesforce/resourceUrl scoped module id */ function isResourceUrlScopedModule(id) { return id && (id.startsWith(RESOURCE_URL_PREFIX) || id.startsWith(CONTENT_ASSET_URL_PREFIX)); } /** * Rollup plugin that resolves @salesforce/resourceUrl/xxx imports to the actual resource URL. * * The returned URL format is `${basePath}/assets/${versionKey}/${resourceName}`. We add `${versionKey}` * to the path to invalidate the HTTP caches when the versionKey changes. */ function plugin() { return { name: 'rollup-plugin-salesforce-resource-urls', /** * Return the code of an ES6 module exporting the actual resource URL, or null * if the id is not a resource URL scoped module id. */ load(id) { if (isResourceUrlScopedModule(id)) { const { versionKey } = getContext(); const [resourceName] = id.split('/')[2].split('.'); return ` import basePath from '@app/basePath'; export default \`\${basePath}/assets/${versionKey}/${resourceName}\`;`; } return null; }, resolveId(id) { return isResourceUrlScopedModule(id) ? id : null; }, }; } exports.default = plugin; //# sourceMappingURL=rollup-plugin-salesforce-resource-url.js.map