mirror of https://github.com/webpack/webpack.git
Compare commits
5 Commits
c12824d4a9
...
a976add629
Author | SHA1 | Date |
---|---|---|
|
a976add629 | |
|
c7dd066327 | |
|
85bacbdc6e | |
|
7634cd28bf | |
|
d5b4b50c10 |
|
@ -300,7 +300,7 @@ module.exports = __webpack_require__.tb("PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmc
|
|||
/******/
|
||||
/******/ /* webpack/runtime/jsonp chunk loading */
|
||||
/******/ (() => {
|
||||
/******/ __webpack_require__.b = (document && document.baseURI) || self.location.href;
|
||||
/******/ __webpack_require__.b = (typeof document !== 'undefined' && document.baseURI) || self.location.href;
|
||||
/******/
|
||||
/******/ // object to store loaded and loading chunks
|
||||
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
|
||||
|
@ -476,10 +476,10 @@ files.forEach(item => {
|
|||
asset output.js 19.2 KiB [emitted] (name: main)
|
||||
asset images/89a353e9c515885abd8e.png 14.6 KiB [emitted] [immutable] [from: images/file.png] (auxiliary name: main)
|
||||
asset images/afc10c70ed4ce2b33593.svg 656 bytes [emitted] [immutable] [from: images/url.svg] (auxiliary name: main)
|
||||
chunk (runtime: main) output.js (main) 12.4 KiB (javascript) 15.2 KiB (asset) 1.46 KiB (runtime) [entry] [rendered]
|
||||
chunk (runtime: main) output.js (main) 12.4 KiB (javascript) 15.2 KiB (asset) 1.48 KiB (runtime) [entry] [rendered]
|
||||
> ./example.js main
|
||||
dependent modules 9.59 KiB (javascript) 15.2 KiB (asset) [dependent] 6 modules
|
||||
runtime modules 1.46 KiB 5 modules
|
||||
runtime modules 1.48 KiB 5 modules
|
||||
./example.js 2.85 KiB [built] [code generated]
|
||||
[no exports]
|
||||
[used exports unknown]
|
||||
|
|
|
@ -286,7 +286,7 @@ export const add = (content, from) => {
|
|||
/******/
|
||||
/******/ /* webpack/runtime/jsonp chunk loading */
|
||||
/******/ (() => {
|
||||
/******/ __webpack_require__.b = (document && document.baseURI) || self.location.href;
|
||||
/******/ __webpack_require__.b = (typeof document !== 'undefined' && document.baseURI) || self.location.href;
|
||||
/******/
|
||||
/******/ // object to store loaded and loading chunks
|
||||
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
|
||||
|
@ -722,7 +722,7 @@ function fibonacci(n) {
|
|||
## Unoptimized
|
||||
|
||||
```
|
||||
asset main.js 11.8 KiB [emitted] (name: main)
|
||||
asset main.js 11.9 KiB [emitted] (name: main)
|
||||
asset workers/fibonacci.js 4.99 KiB [emitted] (name: fibonacci)
|
||||
asset chat.js 839 bytes [emitted] (name: chat)
|
||||
asset 129.js 741 bytes [emitted]
|
||||
|
@ -746,9 +746,9 @@ chunk (runtime: 9a81d90cfd0dfd13d748) workers/fibonacci.js (fibonacci) 176 bytes
|
|||
./fib-worker.js 176 bytes [built] [code generated]
|
||||
[no exports used]
|
||||
new Worker() ./fib-worker.js ./example.js 80:18-84:2
|
||||
chunk (runtime: main) main.js (main) 2.25 KiB (javascript) 5.4 KiB (runtime) [entry] [rendered]
|
||||
chunk (runtime: main) main.js (main) 2.25 KiB (javascript) 5.42 KiB (runtime) [entry] [rendered]
|
||||
> ./example.js main
|
||||
runtime modules 5.4 KiB 7 modules
|
||||
runtime modules 5.42 KiB 7 modules
|
||||
./example.js 2.25 KiB [built] [code generated]
|
||||
[no exports used]
|
||||
entry ./example.js main
|
||||
|
@ -758,7 +758,7 @@ webpack X.X.X compiled successfully
|
|||
## Production mode
|
||||
|
||||
```
|
||||
asset main.js 3.27 KiB [emitted] [minimized] (name: main)
|
||||
asset main.js 3.29 KiB [emitted] [minimized] (name: main)
|
||||
asset workers/fibonacci.js 776 bytes [emitted] [minimized] (name: fibonacci)
|
||||
asset chat.js 270 bytes [emitted] [minimized] (name: chat)
|
||||
asset 129.js 159 bytes [emitted] [minimized]
|
||||
|
@ -782,9 +782,9 @@ chunk (runtime: 9a81d90cfd0dfd13d748) workers/fibonacci.js (fibonacci) 176 bytes
|
|||
./fib-worker.js 176 bytes [built] [code generated]
|
||||
[no exports used]
|
||||
new Worker() ./fib-worker.js ./example.js 80:18-84:2
|
||||
chunk (runtime: main) main.js (main) 2.25 KiB (javascript) 5.4 KiB (runtime) [entry] [rendered]
|
||||
chunk (runtime: main) main.js (main) 2.25 KiB (javascript) 5.42 KiB (runtime) [entry] [rendered]
|
||||
> ./example.js main
|
||||
runtime modules 5.4 KiB 7 modules
|
||||
runtime modules 5.42 KiB 7 modules
|
||||
./example.js 2.25 KiB [built] [code generated]
|
||||
[no exports used]
|
||||
entry ./example.js main
|
||||
|
|
|
@ -1988,6 +1988,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|||
? /** @type {NameForCondition} */ (originModule.nameForCondition())
|
||||
: "",
|
||||
issuerLayer: originModule ? originModule.layer : null,
|
||||
issuerDependency: originModule ? originModule.issuerDependencyType : null,
|
||||
compiler: this.compiler.name,
|
||||
...contextInfo
|
||||
},
|
||||
|
|
|
@ -254,10 +254,12 @@ class ContextModule extends Module {
|
|||
} else if (this.options.namespaceObject) {
|
||||
identifier += "|namespace object";
|
||||
}
|
||||
if (this.options.attributes) {
|
||||
identifier += `|importAttributes: ${JSON.stringify(this.options.attributes)}`;
|
||||
}
|
||||
if (this.layer) {
|
||||
identifier += `|layer: ${this.layer}`;
|
||||
}
|
||||
|
||||
return identifier;
|
||||
}
|
||||
|
||||
|
|
|
@ -335,6 +335,7 @@ class NormalModule extends Module {
|
|||
constructor({
|
||||
layer,
|
||||
type,
|
||||
issuerDependencyType,
|
||||
request,
|
||||
userRequest,
|
||||
rawRequest,
|
||||
|
@ -352,6 +353,7 @@ class NormalModule extends Module {
|
|||
}) {
|
||||
super(type, context || getContext(resource), layer);
|
||||
|
||||
this.issuerDependencyType = issuerDependencyType;
|
||||
// Info from Factory
|
||||
/** @type {string} */
|
||||
this.request = request;
|
||||
|
|
|
@ -514,6 +514,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
context,
|
||||
dependencies,
|
||||
dependencyType,
|
||||
issuerDependencyType,
|
||||
request,
|
||||
attributes,
|
||||
resolveOptions,
|
||||
|
@ -776,6 +777,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
Object.assign(data.createData, {
|
||||
layer:
|
||||
layer === undefined ? contextInfo.issuerLayer || null : layer,
|
||||
issuerDependencyType: issuerDependencyType,
|
||||
request: stringifyLoadersAndResource(
|
||||
allLoaders,
|
||||
resourceData.resource
|
||||
|
@ -864,7 +866,6 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
};
|
||||
continueCallback();
|
||||
}
|
||||
|
||||
// resource without scheme and with path
|
||||
else {
|
||||
const normalResolver = this.getResolver(
|
||||
|
@ -875,6 +876,13 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
"dependencyType",
|
||||
dependencyType
|
||||
)
|
||||
: resolveOptions,
|
||||
issuerDependencyType
|
||||
? cachedSetProperty(
|
||||
resolveOptions || EMPTY_RESOLVE_OPTIONS,
|
||||
"issuerDependency",
|
||||
issuerDependencyType
|
||||
)
|
||||
: resolveOptions
|
||||
);
|
||||
this.resolveResource(
|
||||
|
@ -972,6 +980,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
(dependency).attributes;
|
||||
const dependencyType = dependency.category || "";
|
||||
const contextInfo = data.contextInfo;
|
||||
const issuerDependencyType = dependency.issuerCategory || contextInfo.issuerDependency || null;
|
||||
const fileDependencies = new LazySet();
|
||||
const missingDependencies = new LazySet();
|
||||
const contextDependencies = new LazySet();
|
||||
|
@ -984,6 +993,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
attributes,
|
||||
dependencies,
|
||||
dependencyType,
|
||||
issuerDependencyType,
|
||||
fileDependencies,
|
||||
missingDependencies,
|
||||
contextDependencies,
|
||||
|
@ -1432,10 +1442,11 @@ If changing the source code is not an option there is also a resolve options cal
|
|||
/**
|
||||
* @param {Parameters<ResolverFactory["get"]>[0]} type type of resolver
|
||||
* @param {Parameters<ResolverFactory["get"]>[1]=} resolveOptions options
|
||||
* @param {Parameters<ResolverFactory["get"]>[1]=} issuerResolveOptions options
|
||||
* @returns {ReturnType<ResolverFactory["get"]>} the resolver
|
||||
*/
|
||||
getResolver(type, resolveOptions) {
|
||||
return this.resolverFactory.get(type, resolveOptions);
|
||||
getResolver(type, resolveOptions, issuerResolveOptions) {
|
||||
return this.resolverFactory.get(type, resolveOptions, issuerResolveOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,9 +32,13 @@ const EMPTY_RESOLVE_OPTIONS = {};
|
|||
|
||||
/**
|
||||
* @param {ResolveOptionsWithDependencyType} resolveOptionsWithDepType enhanced options
|
||||
* @param {ResolveOptionsWithDependencyType} issuerResolveOptions enhanced options
|
||||
* @returns {ResolveOptions} merged options
|
||||
*/
|
||||
const convertToResolveOptions = (resolveOptionsWithDepType) => {
|
||||
const convertToResolveOptions = (
|
||||
resolveOptionsWithDepType,
|
||||
issuerResolveOptions
|
||||
) => {
|
||||
const { dependencyType, plugins, ...remaining } = resolveOptionsWithDepType;
|
||||
|
||||
// check type compat
|
||||
|
@ -58,10 +62,24 @@ const convertToResolveOptions = (resolveOptionsWithDepType) => {
|
|||
/** @type {Partial<ResolveOptionsWithDependencyType> & Pick<ResolveOptionsWithDependencyType, "fileSystem">} */ (
|
||||
partialOptions
|
||||
);
|
||||
const { issuerDependency } = issuerResolveOptions;
|
||||
|
||||
const resolvedByDependency = resolveByProperty(
|
||||
options,
|
||||
"byDependency",
|
||||
dependencyType
|
||||
);
|
||||
|
||||
return /** @type {ResolveOptions} */ (
|
||||
// byIssuerDependencyType
|
||||
removeOperations(
|
||||
resolveByProperty(options, "byDependency", dependencyType),
|
||||
issuerDependency
|
||||
? resolveByProperty(
|
||||
resolvedByDependency,
|
||||
"byIssuerDependency",
|
||||
issuerDependency
|
||||
)
|
||||
: resolvedByDependency,
|
||||
// Keep the `unsafeCache` because it can be a `Proxy`
|
||||
["unsafeCache"]
|
||||
)
|
||||
|
@ -93,44 +111,55 @@ module.exports = class ResolverFactory {
|
|||
/**
|
||||
* @param {string} type type of resolver
|
||||
* @param {ResolveOptionsWithDependencyType=} resolveOptions options
|
||||
* @param {ResolveOptionsWithDependencyType=} issuerResolveOptions options
|
||||
* @returns {ResolverWithOptions} the resolver
|
||||
*/
|
||||
get(type, resolveOptions = EMPTY_RESOLVE_OPTIONS) {
|
||||
let typedCaches = this.cache.get(type);
|
||||
if (!typedCaches) {
|
||||
typedCaches = {
|
||||
direct: new WeakMap(),
|
||||
stringified: new Map()
|
||||
};
|
||||
this.cache.set(type, typedCaches);
|
||||
}
|
||||
const cachedResolver = typedCaches.direct.get(resolveOptions);
|
||||
if (cachedResolver) {
|
||||
return cachedResolver;
|
||||
}
|
||||
const ident = JSON.stringify(resolveOptions);
|
||||
const resolver = typedCaches.stringified.get(ident);
|
||||
if (resolver) {
|
||||
typedCaches.direct.set(resolveOptions, resolver);
|
||||
return resolver;
|
||||
}
|
||||
const newResolver = this._create(type, resolveOptions);
|
||||
typedCaches.direct.set(resolveOptions, newResolver);
|
||||
typedCaches.stringified.set(ident, newResolver);
|
||||
get(
|
||||
type,
|
||||
resolveOptions = EMPTY_RESOLVE_OPTIONS,
|
||||
issuerResolveOptions = EMPTY_RESOLVE_OPTIONS
|
||||
) {
|
||||
// let typedCaches = this.cache.get(type);
|
||||
// if (!typedCaches) {
|
||||
// typedCaches = {
|
||||
// direct: new WeakMap(),
|
||||
// stringified: new Map()
|
||||
// };
|
||||
// this.cache.set(type, typedCaches);
|
||||
// }
|
||||
// const cachedResolver = typedCaches.direct.get(resolveOptions);
|
||||
// if (cachedResolver) {
|
||||
// return cachedResolver;
|
||||
// }
|
||||
// const ident = JSON.stringify(resolveOptions);
|
||||
// const resolver = typedCaches.stringified.get(ident);
|
||||
// if (resolver) {
|
||||
// typedCaches.direct.set(resolveOptions, resolver);
|
||||
// return resolver;
|
||||
// }
|
||||
const newResolver = this._create(
|
||||
type,
|
||||
resolveOptions,
|
||||
issuerResolveOptions
|
||||
);
|
||||
// typedCaches.direct.set(resolveOptions, newResolver);
|
||||
// typedCaches.stringified.set(ident, newResolver);
|
||||
return newResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} type type of resolver
|
||||
* @param {ResolveOptionsWithDependencyType} resolveOptionsWithDepType options
|
||||
* @param {ResolveOptionsWithIssuerDependencyType} issuerResolveOptions options
|
||||
* @returns {ResolverWithOptions} the resolver
|
||||
*/
|
||||
_create(type, resolveOptionsWithDepType) {
|
||||
_create(type, resolveOptionsWithDepType, issuerResolveOptions) {
|
||||
/** @type {ResolveOptionsWithDependencyType} */
|
||||
const originalResolveOptions = { ...resolveOptionsWithDepType };
|
||||
|
||||
const resolveOptions = convertToResolveOptions(
|
||||
this.hooks.resolveOptions.for(type).call(resolveOptionsWithDepType)
|
||||
this.hooks.resolveOptions.for(type).call(resolveOptionsWithDepType),
|
||||
issuerResolveOptions
|
||||
);
|
||||
const resolver = /** @type {ResolverWithOptions} */ (
|
||||
Factory.createResolver(resolveOptions)
|
||||
|
|
|
@ -53,6 +53,7 @@ class AssetSourceGenerator extends Generator {
|
|||
|
||||
const encodedSource = originalSource.buffer().toString("base64");
|
||||
|
||||
runtimeRequirements.add(RuntimeGlobals.requireScope);
|
||||
runtimeRequirements.add(RuntimeGlobals.toBinary);
|
||||
|
||||
let sourceContent;
|
||||
|
|
|
@ -1795,12 +1795,17 @@ const getResolveDefaults = ({
|
|||
conditionNames: ["require", "module", "..."],
|
||||
extensions: [...jsExtensions]
|
||||
});
|
||||
/** @type {() => ResolveOptions} */
|
||||
const esmDeps = () => ({
|
||||
/** @type {(options?: { worker?: boolean }) => ResolveOptions} */
|
||||
const esmDeps = ({ worker } = {}) => ({
|
||||
aliasFields: browserField ? ["browser"] : [],
|
||||
mainFields: browserField ? ["browser", "module", "..."] : ["module", "..."],
|
||||
conditionNames: ["import", "module", "..."],
|
||||
extensions: [...jsExtensions]
|
||||
conditionNames: [...(worker ? ["worker"] : []), "import", "module", "..."],
|
||||
extensions: [...jsExtensions],
|
||||
byIssuerDependency: {
|
||||
worker: {
|
||||
conditionNames: ["worker", "import", "module", "..."]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/** @type {ResolveOptions} */
|
||||
|
@ -1823,7 +1828,7 @@ const getResolveDefaults = ({
|
|||
preferRelative: true
|
||||
},
|
||||
worker: {
|
||||
...esmDeps(),
|
||||
...esmDeps({ worker: true }),
|
||||
preferRelative: true
|
||||
},
|
||||
commonjs: cjsDeps(),
|
||||
|
|
|
@ -68,8 +68,8 @@ class ContextElementDependency extends ModuleDependency {
|
|||
*/
|
||||
getResourceIdentifier() {
|
||||
let str = super.getResourceIdentifier();
|
||||
if (this.attributes !== undefined) {
|
||||
str += JSON.stringify(this.attributes);
|
||||
if (this.attributes) {
|
||||
str += `|importAttributes${JSON.stringify(this.attributes)}`;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
|
|
@ -79,8 +79,11 @@ class HarmonyImportDependency extends ModuleDependency {
|
|||
*/
|
||||
getResourceIdentifier() {
|
||||
let str = super.getResourceIdentifier();
|
||||
if (this.attributes !== undefined) {
|
||||
str += JSON.stringify(this.attributes);
|
||||
if (this.defer) {
|
||||
str += "|defer";
|
||||
}
|
||||
if (this.attributes) {
|
||||
str += `|importAttributes${JSON.stringify(this.attributes)}`;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,19 @@ class ImportContextDependency extends ContextDependency {
|
|||
return "esm";
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string | null} an identifier to merge equal requests
|
||||
*/
|
||||
getResourceIdentifier() {
|
||||
let str = super.getResourceIdentifier();
|
||||
|
||||
if (this.options.attributes) {
|
||||
str += `|importAttributes${JSON.stringify(this.options.attributes)}`;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectSerializerContext} context context
|
||||
*/
|
||||
|
|
|
@ -50,8 +50,8 @@ class ImportDependency extends ModuleDependency {
|
|||
*/
|
||||
getResourceIdentifier() {
|
||||
let str = super.getResourceIdentifier();
|
||||
if (this.attributes !== undefined) {
|
||||
str += JSON.stringify(this.attributes);
|
||||
if (this.attributes) {
|
||||
str += `|importAttributes${JSON.stringify(this.attributes)}`;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,10 @@ class WorkerDependency extends ModuleDependency {
|
|||
return "worker";
|
||||
}
|
||||
|
||||
get issuerCategory() {
|
||||
return "worker";
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the hash
|
||||
* @param {Hash} hash hash to be updated
|
||||
|
|
|
@ -134,11 +134,21 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
|||
);
|
||||
if (used) {
|
||||
if (otherUnused || used !== exportInfo.name) {
|
||||
instructions.push(
|
||||
`${external}${propertyAccess([
|
||||
used
|
||||
])} = module${propertyAccess([exportInfo.name])};`
|
||||
);
|
||||
if (exportInfo.name === "default") {
|
||||
// Ideally we should use `module && module.__esModule ? module['default'] : module`
|
||||
// But we need to keep compatibility with SystemJS format libraries (they are using `default`) and bundled SystemJS libraries from commonjs format
|
||||
instructions.push(
|
||||
`${external}${propertyAccess([
|
||||
used
|
||||
])} = module["default"] || module;`
|
||||
);
|
||||
} else {
|
||||
instructions.push(
|
||||
`${external}${propertyAccess([
|
||||
used
|
||||
])} = module${propertyAccess([exportInfo.name])};`
|
||||
);
|
||||
}
|
||||
handledNames.push(exportInfo.name);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
import * as style from "./style.css";
|
||||
import file from "./file.text" with { type: "bytes" };
|
||||
|
||||
it("should work", () => {
|
||||
it("should work", async () => {
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
const text = decoder.decode(file);
|
||||
|
||||
expect(text).toBe("a Ā 𐀀 文 🦄 Text");
|
||||
|
||||
const dyn = (await import("./file.text?other", { with: { type: "bytes" } })).default;
|
||||
const dynText = decoder.decode(dyn);
|
||||
|
||||
expect(dynText).toBe("a Ā 𐀀 文 🦄 Text");
|
||||
|
||||
if (typeof getComputedStyle === "function") {
|
||||
const style = getComputedStyle(document.body);
|
||||
expect(style.getPropertyValue("--my-url")).toBe(" url(data:application/octet-stream;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2MDAgNjAwIj48dGl0bGU+aWNvbi1zcXVhcmUtc21hbGw8L3RpdGxlPjxwYXRoIGZpbGw9IiNGRkYiIGQ9Ik0zMDAgLjFMNTY1IDE1MHYyOTkuOUwzMDAgNTk5LjggMzUgNDQ5LjlWMTUweiIvPjxwYXRoIGZpbGw9IiM4RUQ2RkIiIGQ9Ik01MTcuNyA0MzkuNUwzMDguOCA1NTcuOHYtOTJMNDM5IDM5NC4xbDc4LjcgNDUuNHptMTQuMy0xMi45VjE3OS40bC03Ni40IDQ0LjF2MTU5bDc2LjQgNDQuMXpNODEuNSA0MzkuNWwyMDguOSAxMTguMnYtOTJsLTEzMC4yLTcxLjYtNzguNyA0NS40em0tMTQuMy0xMi45VjE3OS40bDc2LjQgNDQuMXYxNTlsLTc2LjQgNDQuMXptOC45LTI2My4yTDI5MC40IDQyLjJ2ODlsLTEzNy4zIDc1LjUtMS4xLjYtNzUuOS00My45em00NDYuOSAwTDMwOC44IDQyLjJ2ODlMNDQ2IDIwNi44bDEuMS42IDc1LjktNDR6Ii8+PHBhdGggZmlsbD0iIzFDNzhDMCIgZD0iTTI5MC40IDQ0NC44TDE2MiAzNzQuMVYyMzQuMmwxMjguNCA3NC4xdjEzNi41em0xOC40IDBsMTI4LjQtNzAuNnYtMTQwbC0xMjguNCA3NC4xdjEzNi41ek0yOTkuNiAzMDN6bS0xMjktODVsMTI5LTcwLjlMNDI4LjUgMjE4bC0xMjguOSA3NC40LTEyOS03NC40eiIvPjwvc3ZnPg==)");
|
||||
|
|
|
@ -14,5 +14,15 @@ module.exports = {
|
|||
scope.window.document.head.appendChild(link);
|
||||
|
||||
run++;
|
||||
},
|
||||
findBundle(i) {
|
||||
if (i === 2) {
|
||||
return ["bundle2.mjs"];
|
||||
}
|
||||
|
||||
return [
|
||||
`file_text_other.bundle${i}.${i === 2 ? "mjs" : "js"}`,
|
||||
`bundle${i}.${i === 2 ? "mjs" : "js"}`
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"foo": "bar"
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
it("show override request", async () => {
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
const mod = "file.ext";
|
||||
const loadedMod = (await import(`./files/${mod}`, { with: { type: "bytes" } })).default;
|
||||
const text = decoder.decode(loadedMod);
|
||||
|
||||
expect(JSON.parse(text)).toEqual({ foo: "bar" });
|
||||
|
||||
const otherLoadedMod = (await import(`./files/${mod}`, { with: { type: "json" } })).default;
|
||||
|
||||
expect(otherLoadedMod.foo).toBe("bar");
|
||||
});
|
|
@ -0,0 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
const supportsTextDecoder = require("../../../helpers/supportsTextDecoder");
|
||||
|
||||
module.exports = () => supportsTextDecoder();
|
|
@ -0,0 +1,4 @@
|
|||
"use strict";
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {};
|
|
@ -0,0 +1,12 @@
|
|||
const a = 10;
|
||||
const b = 20;
|
||||
|
||||
class MyClass {
|
||||
getValue() {
|
||||
return "my-class";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MyClass;
|
||||
module.exports.a = a;
|
||||
module.exports.b = b;
|
|
@ -0,0 +1,11 @@
|
|||
const a = 10;
|
||||
const b = 20;
|
||||
|
||||
class MyClass {
|
||||
getValue() {
|
||||
return "my-class";
|
||||
}
|
||||
}
|
||||
|
||||
export default MyClass;
|
||||
export { a, b };
|
|
@ -914,5 +914,25 @@ module.exports = (env, { testPath }) => [
|
|||
experiments: {
|
||||
outputModule: true
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: "./esm.js",
|
||||
output: {
|
||||
uniqueName: "system-esm",
|
||||
filename: "system-esm.js",
|
||||
library: {
|
||||
type: "system"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: "./commonjs.js",
|
||||
output: {
|
||||
uniqueName: "system-commonjs",
|
||||
filename: "system-commonjs.js",
|
||||
library: {
|
||||
type: "system"
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
import MyClass, {a, b} from "library-commonjs";
|
||||
|
||||
it("should get exports from systemjs library (" + NAME + ")", function() {
|
||||
expect(new MyClass().getValue()).toBe("my-class")
|
||||
expect(a).toBe(10);
|
||||
expect(b).toBe(20);
|
||||
});
|
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
const System = require("../../../helpers/fakeSystem");
|
||||
|
||||
module.exports = {
|
||||
beforeExecute: () => {
|
||||
System.init();
|
||||
},
|
||||
moduleScope(scope) {
|
||||
scope.System = System;
|
||||
scope.System.setRequire(scope.require);
|
||||
},
|
||||
afterExecute() {
|
||||
delete global.webpackChunk;
|
||||
System.execute("(anonym)");
|
||||
}
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const webpack = require("../../../../");
|
||||
|
||||
/** @type {(env: Env, options: TestOptions) => import("../../../../").Configuration[]} */
|
||||
module.exports = (env, { testPath }) => [
|
||||
{
|
||||
entry: "./system-external-commonjs.js",
|
||||
output: {
|
||||
library: {
|
||||
type: "system"
|
||||
}
|
||||
},
|
||||
externals: {
|
||||
"library-commonjs": path.resolve(
|
||||
testPath,
|
||||
"../0-create-library/system-commonjs.js"
|
||||
)
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
NAME: JSON.stringify("systemjs with external from commonjs format")
|
||||
})
|
||||
]
|
||||
}
|
||||
];
|
|
@ -0,0 +1,7 @@
|
|||
import MyClass, {a, b} from "library-esm";
|
||||
|
||||
it("should get exports from systemjs library (" + NAME + ")", function() {
|
||||
expect(new MyClass().getValue()).toBe("my-class")
|
||||
expect(a).toBe(10);
|
||||
expect(b).toBe(20);
|
||||
});
|
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
const System = require("../../../helpers/fakeSystem");
|
||||
|
||||
module.exports = {
|
||||
beforeExecute: () => {
|
||||
System.init();
|
||||
},
|
||||
moduleScope(scope) {
|
||||
scope.System = System;
|
||||
scope.System.setRequire(scope.require);
|
||||
},
|
||||
afterExecute() {
|
||||
delete global.webpackChunk;
|
||||
System.execute("(anonym)");
|
||||
}
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const webpack = require("../../../../");
|
||||
|
||||
/** @type {(env: Env, options: TestOptions) => import("../../../../").Configuration[]} */
|
||||
module.exports = (env, { testPath }) => [
|
||||
{
|
||||
entry: "./system-external-esm.js",
|
||||
output: {
|
||||
library: {
|
||||
type: "system"
|
||||
}
|
||||
},
|
||||
externals: {
|
||||
"library-esm": path.resolve(testPath, "../0-create-library/system-esm.js")
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
NAME: JSON.stringify("systemjs with external from ES module format")
|
||||
})
|
||||
]
|
||||
}
|
||||
];
|
Loading…
Reference in New Issue