I am a java developer learning EC6. I use npm to download JavaScript packages and webpack to create the final bundle.js file.
I have a nice project folder which contains java modules with java files and I would like to add EC6 JavaScript files to my web-modules. I use maven to manage the java jar dependency libraries.
This is my folder structure:
my-project
|-common-module
|-ejb-module
|-web-module-1
| |-src
| |-main
| |-java
| |-com.a.b
| |-Hello.java
| |-webapp
| |-index.jsp
| |-bundle.js
| |-package.json
| |-webpack.config.js
| |-WEB-INF
| |-node_modules <-- I WANT THIS FOLDER TO BE MOVED AWAY FROM HERE
| |-app <-- react + ec6 javascript files
| |-action
| |-components
| |-...
|-web-module-2
|-<same structure then under web-module-1>
When I execute npm install... command in my-project/web-module-1/src/main/webapp folder then a new directory with name of node_modules is created by npm under webapp directory. This folder contains tons of files.
My problem is that when I work on my 2nd web project and execute the same npm install... command then a second node_modules directory is created with the same content under my-project/web-module-2/src/main/webapp directory.
Can I use a common, separated node_modules directory to avoid the duplicated files and save disk space? Can I store js dependencies under ex. /home/user/javascript/modules folder?
Comment 1: I do not want to execute npm as a root and use npm -g install!
Comment 2: I do not want to create symlinks as well.
Could you please help me?
EDIT What i did:
- I have created a new folder for the JS packages: /home/user/javascript-modules.
- Copied package.json file to /home/user/javascript-modules.
- npm install --prefix /home/user/javascript-modules
After that the necessary JS modules are copied to my javascript-modules/node-modules directory. Nice!
But when I try to execute webpack then i get a missing module error:
- cd my-project/web-module-1/src/main/webapp
- ./home/user/javascript-modules/node_modules/.bin/webpack
Result:
Hash: a6bf1a0d210729a54be9
Version: webpack 1.14.0
Time: 39ms
ERROR in Entry module not found: Error: Cannot resolve module 'babel-loader' in /home/user/java/intellijmy-project/web-module-1/src/main/webapp
Comment: My webpack.config.js files contains a line with this content: loader: 'babel-loader'
Is there any way to specify the "classpath" for webpack? I mean to tell to webpack where are a modules.
UPDATE As you can see in the comments I have tried to solve my issue on many different ways without any success. For me it seems that what I wanted to do is not supported by webpack. That so sad :(
That is it. If some has any working, nice and complete solution please share it with us. Thanks.