forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes webpack#8355
- Loading branch information
Showing
15 changed files
with
124 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
*/ | ||
|
||
"use strict"; | ||
|
||
const createHash = require("../util/createHash"); | ||
const NamedChunkIdsPlugin = require("./NamedChunkIdsPlugin"); | ||
|
||
class HashedChunkIdsPlugin extends NamedChunkIdsPlugin { | ||
constructor(options) { | ||
const nameResolver = NamedChunkIdsPlugin.createDefaultNameResolver({}); | ||
const usedIds = new Set(); | ||
const resolver = chunk => { | ||
const options = this.options; | ||
const name = nameResolver(chunk); | ||
|
||
if (name) { | ||
const hash = createHash(options.hashFunction); | ||
hash.update(name); | ||
const hashId = hash.digest(options.hashDigest); | ||
let len = options.hashDigestLength; | ||
while (usedIds.has(hashId.substr(0, len))) len++; | ||
return hashId.substr(0, len); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
super(resolver); | ||
|
||
this.options = Object.assign( | ||
{ | ||
context: null, | ||
hashFunction: "md4", | ||
hashDigest: "base64", | ||
hashDigestLength: 4 | ||
}, | ||
options | ||
); | ||
} | ||
} | ||
|
||
module.exports = HashedChunkIdsPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require("./modules/a"); | ||
require("./modules/b"); | ||
require("./modules/c"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = "a"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = "b"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = "c"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module.exports = { | ||
mode: "production", | ||
entry: { | ||
entry: "./entry" | ||
}, | ||
optimization: { | ||
moduleIds: "named", | ||
chunkIds: "hashed", | ||
splitChunks: { | ||
cacheGroups: { | ||
vendor: { | ||
name: "vendor", | ||
test: /modules[\\/][ab]/, | ||
chunks: "all", | ||
enforce: true | ||
} | ||
} | ||
} | ||
} | ||
}; |