Issue 1:
Hello,

I'm building a little JS library which is a router to use in RactiveJS web apps.

This library will have two direct dependencies (pagejs and object-assign) and another provided one (ractive itself). The main entry point of the library is its main file, not the bundle file.

I have this library as a NPM module (right now locally) and I have another demo app where I want to use it.

From the demo app, I require RactiveJS because it's an app dependency and I also require my router library.

When I run webpack, Ractive is getting twice into the generated bundle. It seems one for the demo itself and another one for the router library.

I was expecting webpack to be aware that it's the same dependency and thus, only put it once into the bundle.

Am I missing something?

This is the webpack log:

$ webpack -c --display-modules --display-chunks --display-origins -v
Hash: d3d0f28ac53ac87bb2e9
Version: webpack 1.10.5
Time: 3527ms
Asset Size Chunks Chunk Names
./dist/js/app-bundle.js 943 kB 0 [emitted] main
chunk {0} ./dist/js/app-bundle.js (main) 911 kB [rendered]
> main [0] ./app/js/app.js
[0] ./app/js/app.js 2.42 kB {0} [built]
[1] ../ps-ractive-router/src/index.js 193 bytes {0} [built]
cjs require ps-ractive-router [0] ./app/js/app.js 10:23-51
cjs require ps-ractive-router [14] ./app/js/components/home-page.js 10:23-51
cjs require ps-ractive-router [16] ./app/js/components/user-page.js 10:23-51
cjs require ps-ractive-router [33] ./app/js/components/layout/search-user.js 13:23-51
[2] ../ps-ractive-router/src/router-manager.js 990 bytes {0} [built]
cjs require ./router-manager [1] ../ps-ractive-router/src/index.js 3:31-58
cjs require ./router-manager [7] ../ps-ractive-router/src/base-app.js 5:20-47
cjs require ../router-manager [11] ../ps-ractive-router/src/components/base-page-component.js 5:20-48
[3] ../ps-ractive-router/~/page/index.js 14 kB {0} [built]
cjs require page [2] ../ps-ractive-router/src/router-manager.js 3:13-28
[4] (webpack)/~/node-libs-browser/~/process/browser.js 2.02 kB {0} [built]
cjs require process [3] ../ps-ractive-router/~/page/index.js 1:0-160
[5] ../ps-ractive-router/~/page/~/path-to-regexp/index.js 5.06 kB {0} [built]
cjs require path-to-regexp [3] ../ps-ractive-router/~/page/index.js 9:21-46
[6] ../ps-ractive-router/~/page/~/path-to-regexp/~/isarray/index.js 120 bytes {0} [built]
cjs require isarray [5] ../ps-ractive-router/~/page/~/path-to-regexp/index.js 1:14-32
[7] ../ps-ractive-router/src/base-app.js 1.78 kB {0} [built]
cjs require ./base-app [1] ../ps-ractive-router/src/index.js 4:25-46
[8] ../ps-ractive-router/~/ractive/ractive.js 423 kB {0} [built]
cjs require ractive [7] ../ps-ractive-router/src/base-app.js 3:14-32
cjs require ractive [10] ../ps-ractive-router/src/components/router-component.js 3:14-32
cjs require ractive [11] ../ps-ractive-router/src/components/base-page-component.js 3:14-32
[9] ../ps-ractive-router/~/object-assign/index.js 896 bytes {0} [built]
cjs require object-assign [7] ../ps-ractive-router/src/base-app.js 4:19-43
cjs require object-assign [11] ../ps-ractive-router/src/components/base-page-component.js 4:19-43
[10] ../ps-ractive-router/src/components/router-component.js 1.1 kB {0} [built]
cjs require ./components/router-component [7] ../ps-ractive-router/src/base-app.js 6:22-62
[11] ../ps-ractive-router/src/components/base-page-component.js 1.29 kB {0} [built]
cjs require ./components/base-page-component [1] ../ps-ractive-router/src/index.js 5:26-69
[12] ./app/views/app.html 810 bytes {0} [built]
cjs require ../views/app.html [0] ./app/js/app.js 12:20-48
[13] ./app/js/config/routes.js 1.06 kB {0} [built]
cjs require ./config/routes [0] ./app/js/app.js 18:20-46
[14] ./app/js/components/home-page.js 714 bytes {0} [built]
cjs require ../components/home-page [13] ./app/js/config/routes.js 9:26-60
[15] ./app/views/home-page.html 89 bytes {0} [built]
cjs require ../../views/home-page.html [14] ./app/js/components/home-page.js 12:25-62
[16] ./app/js/components/user-page.js 1.74 kB {0} [built]
cjs require ../components/user-page [13] ./app/js/config/routes.js 13:26-60
[17] ./app/views/user-page.html 292 bytes {0} [built]
cjs require ../../views/user-page.html [16] ./app/js/components/user-page.js 12:25-62
[18] ./app/js/components/user/profile-section.js 652 bytes {0} [built]
cjs require ./user/profile-section [16] ./app/js/components/user-page.js 16:26-59
[19] ./~/ractive/ractive.js 423 kB {0} [built]
cjs require ractive [18] ./app/js/components/user/profile-section.js 9:15-33
cjs require ractive [21] ./app/js/components/user/repos-section.js 9:15-33
cjs require ractive [23] ./app/js/components/user/notes-section.js 9:15-33
cjs require ractive [25] ./app/js/components/user/notes/add-note.js 9:15-33
cjs require ractive [31] ./app/js/components/user/notes/notes-list.js 9:15-33
cjs require ractive [33] ./app/js/components/layout/search-user.js 9:15-33
[20] ./app/views/user/profile-section.html 1.32 kB {0} [built]
cjs require ../../../views/user/profile-section.html [18] ./app/js/components/user/profile-section.js 13:35-86
[21] ./app/js/components/user/repos-section.js 842 bytes {0} [built]
cjs require ./user/repos-section [16] ./app/js/components/user-page.js 20:24-55
[22] ./app/views/user/repos-section.html 409 bytes {0} [built]
cjs require ../../../views/user/repos-section.html [21] ./app/js/components/user/repos-section.js 13:33-82
[23] ./app/js/components/user/notes-section.js 958 bytes {0} [built]
cjs require ./user/notes-section [16] ./app/js/components/user-page.js 24:24-55
[24] ./app/views/user/notes-section.html 115 bytes {0} [built]
cjs require ../../../views/user/notes-section.html [23] ./app/js/components/user/notes-section.js 13:33-82
[25] ./app/js/components/user/notes/add-note.js 984 bytes {0} [built]
cjs require ./notes/add-note [23] ./app/js/components/user/notes-section.js 17:20-47
[26] ./app/js/models/user.js 2.8 kB {0} [built]
cjs require ../models/user [13] ./app/js/config/routes.js 17:18-43
cjs require ../../../models/user [25] ./app/js/components/user/notes/add-note.js 13:18-49
[27] ./app/js/plugins/ajax.js 1.57 kB {0} [built]
cjs require ../plugins/ajax [26] ./app/js/models/user.js 13:19-45
[28] ./~/imports-loader?this=>global!./~/exports-loader?global.fetch!./~/whatwg-fetch/fetch.js 8.59 kB {0} [built]
cjs require fetch [27] ./app/js/plugins/ajax.js 1:0-65
[29] ./~/lscache/lscache.js 10.5 kB {0} [built]
cjs require lscache [27] ./app/js/plugins/ajax.js 11:15-33
[30] ./app/views/user/notes/add-note.html 329 bytes {0} [built]
cjs require ../../../../views/user/notes/add-note.html [25] ./app/js/components/user/notes/add-note.js 17:33-86
[31] ./app/js/components/user/notes/notes-list.js 791 bytes {0} [built]
cjs require ./notes/notes-list [23] ./app/js/components/user/notes-section.js 21:22-51
[32] ./app/views/user/notes/notes-list.html 319 bytes {0} [built]
cjs require ../../../../views/user/notes/notes-list.html [31] ./app/js/components/user/notes/notes-list.js 13:35-90
[33] ./app/js/components/layout/search-user.js 1 kB {0} [built]
cjs require ./components/layout/search-user [0] ./app/js/app.js 24:34-76
[34] ./app/views/layout/search-user.html 413 bytes {0} [built]
cjs require ../../../views/layout/search-user.html [33] ./app/js/components/layout/search-user.js 15:33-82

Issue 2:
What is the current behavior?

I defined two aliases B and C, which are outside the main context A. Alias C is referenced from both A and B, which results in duplication of the index.js module only, despite resolving to the same absolute path.

Steps to reproduce.

I have a project with the following file structure:

root
├─ A
│ ├─ package.json
│ ├─ .babelrc
│ ├─ index.js
│ └─ webpack.config.js
└─ elsewhere
└─ B
├─ package.json
├─ .babelrc
└─ index.js
└─ C
├─ package.json
├─ .babelrc
└─ index.js

B and C are defined as aliases in the A webpack config:

resolve: {
alias: {
'B': path.resolve(__dirname + '/../elsewhere/B'),
'C': path.resolve(__dirname + '/../elsewhere/C')
}
},

Both A index.js and B index.js import from C, which is a stateful module that depends on having a single instance in the application.

A index.js

import {doIncrement} from 'C';
import {doDoIncrement} from 'B';

doIncrement();
doDoIncrement();

B index.js

import {doIncrement} from 'C';

export const doDoIncrement = () => {
doIncrement();
}

C index.js (stateful module)

let counter = 0;

export const doIncrement = () => {
counter += 1;
console.log(counter);
}
export default doIncrement;

Program output (expected 1, 2)

1
1

Webpack output

Hash: 40a53bf6a613c92f8df0
Version: webpack 1.14.0
Time: 840ms
Asset Size Chunks Chunk Names
bundle.js 4.57 kB 0 [emitted] main
[0] ./index.js 110 bytes {0} [built]
[1] ../elsewhere/C/index.js 234 bytes {0} [built]
cjs require C [0] ./index.js 3:9-21
[2] ../elsewhere/B/index.js 236 bytes {0} [built]
cjs require B [0] ./index.js 5:9-21
[3] ../elsewhere/C/index.js 234 bytes {0} [built]
cjs require C [2] ../elsewhere/B/index.js 8:9-21

What is the expected behavior?

Since the import of C from both A and B resolve to ../elsewhere/C/index.js, I expect it to not be duplicated.

Workaround

The workaround is to not make the index.js of an aliased folder stateful. You can create another js file e.g. increment.js, and import that into index.js and it will not be duplicated.

Please mention other relevant information such as the browser version, Node.js version, Operating System and programming language.

webpack 1.14.0

node v6.5.0 (but also observed on v7)

Ubuntu 16.04

devDependencies:

"babel-core": "^6.17.0",
"babel-eslint": "^7.1.0",
"babel-loader": "^6.2.5",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-polyfill": "^6.16.0",
"babel-plugin-transform-object-rest-spread": "^6.16.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"babel-register": "^6.16.3",
"webpack": "^1.14.0"

EDIT: full webpack config @ https://gist.github.com/si13b/8e65668e1ac2fe8059e2f0382e02a148)