webpack: Accept a function for filename (#38989)

https://webpack.js.org/configuration/output/#outputfilename

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg
2019-10-09 12:04:29 -07:00
committed by Armando Aguirre
parent 208e84991c
commit fa252d845d
2 changed files with 15 additions and 1 deletions
+6 -1
View File
@@ -17,6 +17,7 @@
// Kyle Uehlein <https://github.com/kuehlein>
// Grgur Grisogono <https://github.com/grgur>
// Rubens Pinheiro Gonçalves Cavalcante <https://github.com/rubenspgcavalcante>
// Anders Kaseorg <https://github.com/andersk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -153,7 +154,7 @@ declare namespace webpack {
/** When used in tandem with output.library and output.libraryTarget, this option allows users to insert comments within the export wrapper. */
auxiliaryComment?: string | AuxiliaryCommentObject;
/** The filename of the entry chunk as relative path inside the output.path directory. */
filename?: string;
filename?: string | ((chunkData: ChunkData) => string);
/** The filename of non-entry chunks as relative path inside the output.path directory. */
chunkFilename?: string;
/** Number of milliseconds before chunk request expires, defaults to 120,000. */
@@ -234,6 +235,10 @@ declare namespace webpack {
type AuxiliaryCommentObject = { [P in LibraryTarget]: string };
interface ChunkData {
chunk: compilation.Chunk;
}
interface Module {
/** A array of applied pre loaders. */
preLoaders?: RuleSetRule[];
+9
View File
@@ -989,3 +989,12 @@ webpack.Template.renderChunkModules(
[],
'a',
);
// https://webpack.js.org/configuration/output/#outputfilename
configuration = {
output: {
filename: chunkData => {
return chunkData.chunk.name === 'main' ? '[name].js' : '[name]/[name].js';
},
},
};