Closed astik closed 9 years ago
Seems weird that you get _nodemodules in project root - can you post your configuration? node_modules should end up in target-grunt as well by default.
Will post an example where we can reproduce this issue. Still, even if node_modules should be in target-grunt, package.json is into project root and is readable by the plugin ; I was expecting bower.json to be readable as well.
I just would like to see the config, because it seems unlikely that gmp picked up package.json from root by default - it just doesn't do this :P
Picks up package.json from root ootb for me as well.
Hi all, i finally managed to reproduce the problem into a little isolated project : https://github.com/astik/grunt-maven-plugin-bug69 You should have all information needed in the README to reproduce.
Thanks for the example, let me clarify things.
First things first, i know why package.json seems to be picked up from root when calling npm install. It seems (although i can't see it in official documentation) that when calling npm it looks for either _nodemodules or package.json in current directory and it parents, all the way to / (btw this is similar to gradle behavior). So, in this specific case directory layout looks like this:
src/
target/
target-grunt/ <- this is where npm install is called
package.json
pom.xml
npm install
is called in target-grunt. Since you didn't have any package.json in src/main/webapp/static/, none is present in target-grunt as well. npm goes to parent directory and finds package.json, creating _nodemodules in project root:
node_modules/ <- this was created by npm, but it should be in target grunt!
src/
target/
target-grunt/
package.json
pom.xml
_nodemodules is created in wrong place. It might seem like build is okay, but then bower can't find it's configuration, because it does not use same algorithm as npm. bower looks for package definitions in directory it was called in, target-grunt in this case.
So, to the what is wanted. This plugin was created with certain philosophy in background - separating Java and JS builds. So package.json and bower.json (and any other files) are copied from src/main/webapp/
But what you probably had in mind was having _nodemodules in project root (or any other directory). This is not the scenario that gmp will support. I think you might take a look at sandbox project, run it and see the results - pay attention how files are copied from src to target-grunt. Then decide if this is workflow that suits your needs.
Ok, First of all, thanks a lot for the long and deep answer you gave me, it is clear now that I'm not using your plugin the way I should. The thing I miss was that "sourceDirectory/jsSourceDirectory" is in fact not only the source folder for my JS but for the whole static project. Having that information in mind makes obvious the need for package.json and bower.json in this particular folder. So, it leads to the thing that bothers me : if you use npm+grunt+bower directly in the "sourceDirectory/jsSourceDirectory" folder to work only on static ressource (frontend workflow only for dev purpose), you will have the node_modules and bower_components into the source folder, of course having them in ignore will prevent them to be versionned. But, as they will be copied to "target-grunt", it will be a long copy process. This is why I was hoping to externalize those 2 dependencies folders. Anyway, as you say, my need may not be in accordance with GMP philosophy. I gadly appreciate the time you have taken to explain it why =) I close the issue as, in fact, it is not one.
Wait a minute :) Copying works only with pure sources, before build is run. So:
src/main/webapp/static/package.json
src/main/webapp/static/bower.json
gets copied to:
target-grunt/package.json
target-grunt/bower.json
and then npm install and bower install get run, which will result in:
target-grunt/package.json
target-grunt/bower.json
target-grunt/node_modules
target-grunt/bower_components
This means that there is no long copy process. In fact copying is really quick here - we use this plugin in few quite big projects and copying sources was never a problem.
Sure, but what about all other files from src/main/webapp/static ?
For example, consider this source file structure :
src/main/webapp/static/package.json
src/main/webapp/static/bower.json
src/main/webapp/static/app/js
src/main/webapp/static/app/css
src/main/webapp/static/app/img
src/main/webapp/static/app/index.html
If I go to src/main/webapp/static/ and would like to use the serve task from grunt, I will need to get all dependencies first :
cd src/main/webapp/static/app/
npm install
bower install
grunt serve
That will lead to the creation of 2 folders :
src/main/webapp/static/node_modules
src/main/webapp/static/bower_components
That is OK for dev purpose. But once I want to package all of this, the 2 latest folders would get copied too with the rest of the folder, right ?
Please take a look at development options: https://github.com/allegro/grunt-maven-plugin#mavengrunt-integrated-workflow . We have ways to develop stuff without creating these two last directories.
Hi all,
I have a regular project structure :
While using mvn grunt:npm, everything is ok, dependencies are fetched into ROOT/node_modules.
But when running *mvn grunt:bower", it leads to an error :
Which is weird as bower.json is quite present into ROOT.
After playing a bit with the plugin and files, I found that when putting bower.json into target-grunt, the bower task is working ...
I think it is a bug as npm and bower should work the same way.
Am I missing something ?