Issue 1:
Sorry, long post :)

I know this project is webpack, though it seems to have quite a lot of features (well done by the way). I've started writing a node packer (and I came up with a similar bootstrapper to yours). I had the grand goal of packing (in a similar flat file as yours) an entire application, with all of its dependencies. After a couple days working on it, it seems like there are many difficult corner cases. Such as:

var app = express()
app.use(express.static(__dirname + '/../static')); //lack of path.join

At compile time, you could calculate which directory static is, though you wouldn't know what express, for example, is doing with it. My solution was to force each module to specify it's static files using a glob like: ./static/**. Then there's the problem of where to copy all these static files. They can't go next the bundle.js, with 40+ modules, there would be a clash. So then you need to namespace static files, and rewrite all file references. I think the optimal solution for the filesystem stuff is to dynamically rewrite the fs module to modify filepaths before passing them to the real fs methods.

After running into many problems, introducing exceptions for each disallowed case, dynamic requires, etc. Forcing a manifest.

I'm modified my packer to now just do a directory copy, with the ability to rewrite the source. like change my-secret-module.js to x.js and all requires to x too. While minifying ofcourse. I plan to do like a "progressive enhancement" of packing. So start a normal directory copy, though when possible, compress filenames, flatten modules, etc. Optimally, I'd like no manifest file, and if you write your JS in an analysable way, the packer will pack tighter, if not it'll still work.

Just wondering on your thoughts about Node.js, I know it's not your target, though many companies would be interested in getting it right, since it would allow for safer (even though it's not perfect) distribution.

I originally came up with the same module number indexing scheme. Though I moved to full-path hashing + hash compression. So, my/path/to/file.js might hash to aef83c1........, and another might hash to a2d553...... After all hashes have been calculated. You can compress them all. The above two would compress to ae and a2. With hashing, it allows you to convert require(myvar) into require(__hash(myvar)). Though there are still a few issues, like calculating the fullpath from a module requires you to store the path along side the module. However, I think this could be solved with some more cryptomagic. If you're happy with indices, instead of using an object {0:a 1:b 2:c }, you can equivalently use array [ a, b, c] - save a few bytes.

Issue 2:
Feature request

Here is the bug-ish issue I'm running into:

https://github.com/jedwards1211/webpack-code-splitting-issue/tree/two-async-chunks

index.js

import('./chunk1.js')
import('./chunk2.js')

chunk1.js

import { Toggle } from 'react-powerplug';
console.log(Toggle)

chunk2.js

import { Value } from 'react-powerplug';
console.log(Value)

webpack.config.js

// webpack.config.js
module.exports = {
mode: 'production',
externals: {
'react': 'React'
},
}

webpack it on the command line

What is the expected behavior?

dist/1.js contains Toggle but not Value.

dist/2.js contains Value but not Toggle.

Current behavior

dist/1.js contains both Toggle and Value.

dist/2.js contains both Toggle and Value.

It seems that the tree shaking is applied to react-powerplug main module itself, irrespective of the individual chunks that are importing from it.

What is motivation or use case for adding/changing the behavior?

Many packages nowadays use rollup to bundle their code into a single JS module and distribute that one file (or maybe one bundle for ES5, one bundle for ES2015). As such, I want to be confident that Webpack will eliminate dead code effectively when several different chunks of my app are importing from a rollup bundle.

How should this be implemented in your opinion?

Hopefully, tree-shaking can be performed on react-powerplug for the import in chunk1.js, and then a second, different round of tree-shaking can be performed for the import in chunk2.js. Right now it seems like Webpack is only performing one tree-shaking operation on react-powerplug based upon all imports from it from all chunks in my app.

Are you willing to work on this yourself?

I would need a lot of guidance, as this seems like this might require a significant refactor