isolated-externals-plugin
Advanced tools
Comparing version 2.2.0 to 2.3.0-global-url-modifier-3cd931d.1
export interface ExternalInfo { | ||
globalName?: string; | ||
url: string; | ||
urlTransformer?: string; | ||
} | ||
@@ -8,2 +9,8 @@ export interface Externals { | ||
} | ||
export type ModuleExternalInfo = Omit<ExternalInfo, 'urlTransformer'> & { | ||
urlTransformer: (url: string) => string; | ||
}; | ||
export interface ModuleExternals { | ||
[key: string]: ModuleExternalInfo; | ||
} | ||
type GuaranteedCache = Pick<Cache, 'match' | 'put' | 'add'>; | ||
@@ -10,0 +17,0 @@ type CacheLike = Partial<Cache> & GuaranteedCache; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var lastClosingCurly = /}([^}]*)$/; | ||
function default_1(source) { | ||
var externals = this.getOptions(); | ||
var newSource = source.replace(/ISOLATED_EXTERNALS_OBJECT/, JSON.stringify(externals, null, 2)); | ||
var translatedExternals = Object.keys(externals).reduce(function (finalExternals, key) { | ||
var external = externals[key]; | ||
var externalTransformer = external.urlTransformer; | ||
var urlTransformer = externalTransformer | ||
? "require('".concat(externalTransformer, "')") | ||
: 'function (x) { return x; }'; | ||
var transformedExternal = Object.keys(external).reduce(function (modifiedExternal, key) { | ||
var _a; | ||
return key === 'urlTransformer' | ||
? modifiedExternal | ||
: __assign(__assign({}, modifiedExternal), (_a = {}, _a[key] = external[key], _a)); | ||
}, {}); | ||
var stringExternal = JSON.stringify(transformedExternal, null, 2); | ||
var urlTransformerExternal = stringExternal.replace(lastClosingCurly, ", \"urlTransformer\": ".concat(urlTransformer, "}")); | ||
return finalExternals.replace(lastClosingCurly, "\"".concat(key, "\": ").concat(urlTransformerExternal, ",}")); | ||
}, '{}'); | ||
var newSource = source.replace(/ISOLATED_EXTERNALS_OBJECT/, translatedExternals); | ||
return newSource; | ||
} | ||
exports.default = default_1; |
@@ -1,6 +0,9 @@ | ||
import { Externals } from './externalsClasses'; | ||
import { ModuleExternals } from './externalsClasses'; | ||
type URLModifier = (url: string) => string; | ||
declare global { | ||
const ISOLATED_EXTERNALS_OBJECT: Externals; | ||
const ISOLATED_EXTERNALS_OBJECT: ModuleExternals; | ||
const URL_TRANSFORMER: URLModifier; | ||
const __webpack_modules__: Record<string, unknown>; | ||
} | ||
export declare const externals: Record<string, unknown>; | ||
export {}; |
@@ -92,7 +92,8 @@ "use strict"; | ||
var externalsContext = {}; | ||
var externalsObject = Object.entries(externalsInfo).reduce(function (extObj, _a) { | ||
var _b = __read(_a, 2), _c = _b[1], url = _c.url, globalName = _c.globalName; | ||
var externalsObject = Object.values(externalsInfo).reduce(function (extObj, _a) { | ||
var url = _a.url, globalName = _a.globalName, urlTransformer = _a.urlTransformer; | ||
if (!globalName) | ||
return extObj; | ||
var externalLoad = loadExternal(externalsContext, url, orderedDeps); | ||
var targetGlobal = (0, getGlobal_1.default)(); | ||
var externalLoad = loadExternal(externalsContext, urlTransformer(url), orderedDeps); | ||
orderedDeps = __spreadArray(__spreadArray([], __read(orderedDeps), false), [externalLoad], false); | ||
@@ -108,3 +109,3 @@ Object.defineProperty(extObj, globalName, { | ||
return [2 /*return*/, ((0, getValue_1.default)(globalName, foundContext) || | ||
(0, getValue_1.default)(globalName, (0, getGlobal_1.default)()))]; | ||
(0, getValue_1.default)(globalName, targetGlobal))]; | ||
} | ||
@@ -111,0 +112,0 @@ }); |
{ | ||
"name": "isolated-externals-plugin", | ||
"version": "2.2.0", | ||
"version": "2.3.0-global-url-modifier-3cd931d.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -66,10 +66,15 @@ # isolated-externals-plugin | ||
| Part | Description | | ||
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `entryName`\* | The name of one of your webpack [Entry Points](https://webpack.js.org/concepts/entry-points/). | | ||
| `packageName`\* | The name of the import for your externalized dependency (like 'react-dom'). | | ||
| `url`\* | The URL from which to load your dependency file. | | ||
| `globalName` | The UMD name of your dependency (like `ReactDOM`). If this is not provided, `IsolatedExternalsPlugin` will try to match the `packageName` to one of your [`externals`](https://webpack.js.org/configuration/externals/#externals) entries, and will use the value from that as the `globalName` | | ||
| \* | _required_ | | ||
| Part | Description | | ||
| ---------------- | --------------------------------------------------------------------------------------------------------- | | ||
| `entryName`\* | The name of one of your webpack [Entry Points](https://webpack.js.org/concepts/entry-points/). | | ||
| `packageName`\* | The name of the import for your externalized dependency (like 'react-dom'). | | ||
| `url`\* | The URL from which to load your dependency file. | | ||
| `globalName` | The UMD name of your dependency (like `ReactDOM`). [See below for details](#globalname-and-other-details) | | ||
| `urlTransformer` | A path or module path to a module that exports a url transforming function. | | ||
| \* | _required_ | | ||
## `globalName` and other details | ||
If `globalName` is not provided, `IsolatedExternalsPlugin` will try to match the `packageName` to one of your [`externals`](https://webpack.js.org/configuration/externals/#externals) entries, and will use the value from that as the `globalName` | ||
The external files will be loaded and applied to your context in the order that they're listed, so if you have dependencies that depend on other dependencies (like `ReactDOM` depends on `React`), then you'll want to make sure you list the ones they depend on first. | ||
@@ -76,0 +81,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
55167
1063
104
1