Webpack multiple requires permission to the same file, but is imported twice

Hello, I 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 working on the same file. However, if you look in the output package, there are two different webpack functions with the same content. I'm 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 this, or am I missing something?

Btw I need this because it causes several problems with angularjs that my controllers do not detect.

+7
javascript angularjs webpack require
source share
1 answer

You can just use DedupePlugin. It searches if the module is already included in your assembly, and if so, then it does not include it again. It is easy to configure and you do not need to require or install anything extra.

 var webpack = require("webpack"); module.exports = { // more of your config // ... plugins: [ new webpack.optimize.DedupePlugin() ] }; 
+2
source share

All Articles