Merge remote-tracking branch 'origin/next' into next
This commit is contained in:
commit
2e25cd588b
|
@ -1118,7 +1118,9 @@ export interface OutputOptions {
|
|||
/**
|
||||
* The filename of asset modules as relative path inside the `output.path` directory.
|
||||
*/
|
||||
assetModuleFilename?: string;
|
||||
assetModuleFilename?:
|
||||
| string
|
||||
| ((pathData: import("../lib/Compilation").PathData) => string);
|
||||
/**
|
||||
* Add a comment in the UMD wrapper.
|
||||
*/
|
||||
|
|
|
@ -2515,15 +2515,30 @@ class Compilation {
|
|||
const usedHash = fileManifest.hash;
|
||||
|
||||
this.cache.get(cacheName, usedHash, (err, sourceFromCache) => {
|
||||
let filenameTemplate, file;
|
||||
/** @type {string | function(PathData): string} */
|
||||
let filenameTemplate;
|
||||
/** @type {string} */
|
||||
let file;
|
||||
|
||||
let inTry = true;
|
||||
const errorAndCallback = err => {
|
||||
const filename =
|
||||
file ||
|
||||
(typeof filenameTemplate === "string"
|
||||
? filenameTemplate
|
||||
: "");
|
||||
|
||||
this.errors.push(new ChunkRenderError(chunk, filename, err));
|
||||
inTry = false;
|
||||
return callback();
|
||||
};
|
||||
|
||||
try {
|
||||
filenameTemplate = fileManifest.filenameTemplate;
|
||||
file = this.getPath(filenameTemplate, fileManifest.pathOptions);
|
||||
|
||||
if (err) {
|
||||
this.errors.push(
|
||||
new ChunkRenderError(chunk, file || filenameTemplate, err)
|
||||
);
|
||||
return callback();
|
||||
return errorAndCallback(err);
|
||||
}
|
||||
|
||||
let source = sourceFromCache;
|
||||
|
@ -2532,6 +2547,7 @@ class Compilation {
|
|||
const alreadyWritten = alreadyWrittenFiles.get(file);
|
||||
if (alreadyWritten !== undefined) {
|
||||
if (alreadyWritten.hash !== usedHash) {
|
||||
inTry = false;
|
||||
return callback(
|
||||
new WebpackError(
|
||||
`Conflict: Multiple chunks emit assets to the same filename ${file}` +
|
||||
|
@ -2558,6 +2574,7 @@ class Compilation {
|
|||
}
|
||||
}
|
||||
if (this.assets[file] && this.assets[file] !== source) {
|
||||
inTry = false;
|
||||
return callback(
|
||||
new WebpackError(
|
||||
`Conflict: Rendering chunk ${chunk.id} ` +
|
||||
|
@ -2580,15 +2597,17 @@ class Compilation {
|
|||
chunk
|
||||
});
|
||||
if (source !== sourceFromCache) {
|
||||
this.cache.store(cacheName, usedHash, source, callback);
|
||||
this.cache.store(cacheName, usedHash, source, err => {
|
||||
if (err) return errorAndCallback(err);
|
||||
return callback();
|
||||
});
|
||||
} else {
|
||||
inTry = false;
|
||||
callback();
|
||||
}
|
||||
} catch (err) {
|
||||
this.errors.push(
|
||||
new ChunkRenderError(chunk, file || filenameTemplate, err)
|
||||
);
|
||||
return callback();
|
||||
if (!inTry) throw err;
|
||||
errorAndCallback(err);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
|
@ -53,7 +53,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|||
/**
|
||||
* @typedef {Object} RenderManifestEntry
|
||||
* @property {function(): Source} render
|
||||
* @property {string=} filenameTemplate
|
||||
* @property {string | function(PathData): string} filenameTemplate
|
||||
* @property {PathData=} pathOptions
|
||||
* @property {string} identifier
|
||||
* @property {string=} hash
|
||||
|
|
|
@ -983,8 +983,16 @@
|
|||
"properties": {
|
||||
"assetModuleFilename": {
|
||||
"description": "The filename of asset modules as relative path inside the `output.path` directory.",
|
||||
"type": "string",
|
||||
"absolutePath": false
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"absolutePath": false
|
||||
},
|
||||
{
|
||||
"instanceof": "Function",
|
||||
"tsType": "((pathData: import(\"../lib/Compilation\").PathData) => string)"
|
||||
}
|
||||
]
|
||||
},
|
||||
"auxiliaryComment": {
|
||||
"description": "Add a comment in the UMD wrapper.",
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
import png from "../_images/file.png";
|
||||
import svg from "../_images/file.svg";
|
||||
|
||||
it("should change filenames", () => {
|
||||
expect(png).toEqual("images/success-png.png");
|
||||
expect(svg).toEqual("images/success-svg.svg");
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
module.exports = {
|
||||
mode: "development",
|
||||
output: {
|
||||
assetModuleFilename: ({ filename }) => {
|
||||
if (/.png$/.test(filename)) {
|
||||
return "images/success-png[ext]";
|
||||
}
|
||||
if (/.svg$/.test(filename)) {
|
||||
return "images/success-svg[ext]";
|
||||
}
|
||||
return "images/failure[ext]";
|
||||
}
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(png|svg)$/,
|
||||
type: "asset"
|
||||
}
|
||||
]
|
||||
},
|
||||
experiments: {
|
||||
asset: true
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue