Hello I just had this problem with webpack. If I do require('../something')
from one file, and then I do require('../../something')
in another file they both end up resolving to the same file. However if you look in the output bundle there are two different webpack functions both with the same content. I'm pretty sure I can use an alias to fix this and then just do require('something')
in both files. But is this the right way to do it or am I missing something?
Btw I need this because it's causing several problems with angularjs undefining my controllers.
The rules are quite simple: the same module is evaluated only once, in other words, the module-level scope is executed just once. If the module, once evaluated, is imported again, it's second evaluation is skipped and the resolved already exports are used.
webpack.config.jsWe can also pass an array of file paths to the entry property which creates what is known as a "multi-main entry". This is useful when you would like to inject multiple dependent files together and graph their dependencies into one "chunk".
The entry object is where webpack looks to start building the bundle. The context is an absolute string to the directory that contains the entry files.
You can just use the DedupePlugin. It looks for if the module has already been included in your build and if so, doesn't include it again. It's easy to set up and you don't need to require or install anything extra.
var webpack = require("webpack");
module.exports = {
// more of your config
// ...
plugins: [
new webpack.optimize.DedupePlugin()
]
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With