You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I haven't tried it yet, but does webpack reduce dependencies according to the package version? So if a module with the same version number is included from two different directories, e.g. A/node_modules/[email protected] and B/node_modules/[email protected], webpack should include it only once into the bundle.
It would be even better if webpack includes only one version as long as the major version of those two dependencies don't differ. So if myLib1 depends on [email protected] and myLib2 depends on [email protected], webpack should include only [email protected] because - according to semver - it won't break myLib2. Maybe this should be opt-in as it is potential risky.
In any case webpack should log a warning if two versions of the same module are included.
You can try npm dedupe, according to the documentation it should merge modules with the same (similar) version number. (Not tested yet)
Merging modules with different versions is very risky.
A similar feature is in my mind for a long time: Finding modules with the same code, but maybe different depedencies and merging them. At runtime I would include only a reference to the shared code and a dependency mapping table. It is a bit complex to implement, but this wouldn't break anything.
A small note: even merging modules with exact the same version can break something. If you rely on being the only user of you local module and the module has some static state. (very rar and bad style)
It is risky - that's why it should be opt-in. But I don't think that bundling two different versions of e.g. underscore for the client is the right thing to do.
But you're right: This could also be the job of npm when deploying the application. You may close this one or keep it open as a reminder.
Btw: components keeps the dependency hierarchy flat. I think, both styles - deep (npm) and flat (component) - are appropriate for their targeted environment.
I'll only perform safe optimization. If enabled a hash over each module source code (before dependencies) will detect duplicates. Dependencies can and will be different.
An example without dependencies:
node_modules/a/file.js -> module id 1
node_mdoules/b/node_modules/a/file.js -> module id 2
So, first using npm dedupe to reduce the dependencies according to semver and then webpack's dedupe to remove duplication on file-level (if there are some remaining) will probably have the best result.
Activity
sokra commentedon Jan 14, 2013
You can try npm dedupe, according to the documentation it should merge modules with the same (similar) version number. (Not tested yet)
Merging modules with different versions is very risky.
A similar feature is in my mind for a long time: Finding modules with the same code, but maybe different depedencies and merging them. At runtime I would include only a reference to the shared code and a dependency mapping table. It is a bit complex to implement, but this wouldn't break anything.
A small note: even merging modules with exact the same version can break something. If you rely on being the only user of you local module and the module has some static state. (very rar and bad style)
sokra commentedon Jan 14, 2013
Definitly not in 0.9
jhnns commentedon Jan 14, 2013
It is risky - that's why it should be opt-in. But I don't think that bundling two different versions of e.g.
underscorefor the client is the right thing to do.But you're right: This could also be the job of npm when deploying the application. You may close this one or keep it open as a reminder.
Btw: components keeps the dependency hierarchy flat. I think, both styles - deep (npm) and flat (component) - are appropriate for their targeted environment.
jhnns commentedon Apr 4, 2013
This will now become relevant as we're trying to split alamid in different modules.
sokra commentedon Apr 4, 2013
This will come...
sokra commentedon Apr 4, 2013
Here is the planned deduplication code. See it as riddle...
EDIT: use
Array.prototype.concatjhnns commentedon Apr 4, 2013
Looks good! Slice, unshift, apply - that's the way we go! 👍
michaelficarra commentedon Apr 4, 2013
Should be concat.
sokra commentedon Apr 4, 2013
I thought
Array.prototype.concatisn't supported by IE6, but I think I was wrong... So it could be optimized a bit 😄 thanksjhnns commentedon Apr 8, 2013
Could you tell us a bit about your plans? I think this is a hot topic that needs to be discussed as it's not trivial.
sokra commentedon Apr 8, 2013
I'll only perform safe optimization. If enabled a hash over each module source code (before dependencies) will detect duplicates. Dependencies can and will be different.
An example without dependencies:
node_modules/a/file.js-> module id 1node_mdoules/b/node_modules/a/file.js-> module id 2With the source:
would result in
The above code fragment than transform this array.
With dependencies it is a bit complexer:
node_modules/a/index.js-> module id 3node_mdoules/b/node_modules/a/index.js-> module id 4With the source:
Would result in
jhnns commentedon Apr 8, 2013
So the code is not duplicated but
require("a")returns a different instance thanrequire("b/node_modules/a")? Is semver taking into account?sokra commentedon Apr 8, 2013
yes. No.
I think semver is too high level for webpack... It's working on file level, while semver is package level... semver is the job of npm.
jhnns commentedon Apr 8, 2013
So how do you decide that two modules are the same? String comparison?
sokra commentedon Apr 8, 2013
yes, maybe optimized with a hash. Maybe I'll compare after minimizing...
added experimental deduplication support #47
sokra commentedon Jun 12, 2013
0.10.0-beta20 has experimental support.
--optimize-dedupeThere is some stuff missing. Webpack may exit with a "Template cannot be applied as TemplateArgument" exception.
jhnns commentedon Jun 12, 2013
Nice .. 👍
sokra commentedon Jun 13, 2013
Here is an example: https://github.com/webpack/webpack/tree/master/examples/dedupe
sokra commentedon Jun 13, 2013
And another with code splitting: https://github.com/webpack/webpack/tree/master/examples/code-splitted-dedupe
jhnns commentedon Jun 14, 2013
So, first using
npm dedupeto reduce the dependencies according to semver and then webpack's dedupe to remove duplication on file-level (if there are some remaining) will probably have the best result.fix(html): read a script type through the parser's own decoding
fix(html): read a script type through the parser's own decoding
fix(html): read a `<script type>` decoded, and trim an inline script
fix(html): drop the inline-script trim, keep the decoded type
fix(html): read a <script type> decoded, and trim an inline script (#…