In the webpack examples, in particular
- https://github.com/webpack/webpack/tree/master/examples/dll
- https://github.com/webpack/webpack/tree/master/examples/dll-user
We can create a bundle that depends on already pre-bundled libraries.
The examples at hand work as they should. That is, we first navigate
to examples/dll
and run node build.js
to create the libraries. Then we navigate to examples/dll-user
and run node build.js
to create our final bundles that reference the previously bundled libraries.
My question is the following. Suppose that in examples/dll
we modify the configuration file to look as follows:
var path = require("path");
var webpack = require("../../");
module.exports = {
entry: {
alpha: ["./alpha", "./a", "module"],
beta: ["./beta", "./b", "module"]
},
output: {
path: path.join(__dirname, "js"),
filename: "MyDll.[name].js",
library: "[name]_[hash]"
},
plugins: [
new webpack.DllPlugin({
path: path.join(__dirname, "js", "[name]-manifest.json"),
name: "[name]_[hash]"
})
]
};
That is, we added module
to the beta
dll. Now we have to dlls that have module
. Lets compile the dlls and move on to dll-user
example. Here what we would like to do is make a bundle from which we can choose the library that will provide module
. Lets try adding one more line to the example
console.log(require("../dll/alpha"));
console.log(require("../dll/a"));
console.log(require("beta/beta"));
console.log(require("beta/b"));
console.log(require("module"));
console.log(require("beta/module"));
In this case I want to be able to use the module
that resides in the beta
dll. Unfortunately I was not lucky. This is the output I obtain after trying it:
jmlopez in ~/Downloads/webpack-master/examples/dll-user$ node build.js
{ [Error: Command failed: /bin/sh -c node ../../bin/webpack.js --display-reasons --display-chunks --display-modules --display-origins --output-public-path "js/" -p ./example.js js/output.js
]
killed: false,
code: 2,
signal: null,
cmd: '/bin/sh -c node ../../bin/webpack.js --display-reasons --display-chunks --display-modules --display-origins --output-public-path "js/" -p ./example.js js/output.js' }
Hash: bd42dda7e56ebfd7cd32
Version: webpack 2.1.0-beta.6
Time: 68ms
Asset Size Chunks Chunk Names
output.js 4.26 kB 0 [emitted] main
chunk {0} output.js (main) 504 bytes [rendered]
> main [7] ./example.js
[7] ./example.js 210 bytes {0} [built] [1 error]
+ 7 hidden modules
ERROR in ./example.js
Module not found: Error: Can't resolve 'beta/module' in '/Users/jmlopez/Downloads/webpack-master/examples/dll-user'
@ ./example.js 8:12-34
{ [Error: Command failed: /bin/sh -c node ../../bin/webpack.js --display-reasons --display-chunks --display-modules --display-origins --output-public-path "js/" --output-pathinfo ./example.js js/output.js
]
killed: false,
code: 2,
signal: null,
cmd: '/bin/sh -c node ../../bin/webpack.js --display-reasons --display-chunks --display-modules --display-origins --output-public-path "js/" --output-pathinfo ./example.js js/output.js' }
Is there any way to specify the library that the bundle should use? I thought the scope
option in DllReferencePlugin
would do the trick but it doesn't seem to be the case.
EDIT: Note that adding ./a
to the beta dll and then using require('beta/a')
in the example works. It seems that webpack has a hard time figuring it out the node_modules.