-
-
Save Retsam/f1eb7f754f9649cf7f686c26e6e8ad71 to your computer and use it in GitHub Desktop.
Webpack CommonsChunkPlugin issue
This file contains hidden or 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
| import c from "./c"; | |
| export default "a" + c; |
This file contains hidden or 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
| import c from "./c"; | |
| export default "b" + c; |
This file contains hidden or 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
| export default "c"; |
This file contains hidden or 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
| export default "d"; |
This file contains hidden or 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
| //A and B are largely the same code (shared dependency on C) | |
| require.ensure([], (require) => { | |
| const a = require("./a").default; | |
| console.log("Got a", a) | |
| }, "aChunk"); | |
| require.ensure([], (require) => { | |
| const b = require("./b"); | |
| console.log("Got b", b) | |
| }, "bChunk"); | |
| // D is unrelated to A or B (no shared code), but prevents any code from being extracted from A or B | |
| require.ensure([], (require) => { | |
| const d = require("./d"); | |
| console.log("Got d", d); | |
| }, "dChunk"); |
This file contains hidden or 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
| const path = require("path"); | |
| const webpack = require("webpack"); | |
| module.exports = { | |
| entry: "./main", | |
| output: { | |
| filename: "bundle.js", | |
| chunkFilename: "[name].bundle.js", | |
| path: path.resolve("dist") | |
| }, | |
| plugins: [ | |
| new webpack.optimize.CommonsChunkPlugin({ | |
| name: "main", | |
| async: "common" | |
| }) | |
| ] | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running this as is, I expect to see common code from aChunk and bChunk to have been extracted, but it hasn't:
If I comment out lines 13-16 (where d is required), however, I get the expected behavior: