I am refactoring an existing javascript project into Maven and am having problems getting my head around dealing with the different files.
I am using the jasmine-maven-plugin
which looks a bit like this in my pom.xml:
<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>1.0.1-beta-6</version>
<executions>
<execution>
<goals>
<goal>generateManualRunner</goal>
<goal>resources</goal>
<goal>testResources</goal>
<goal>test</goal>
<goal>preparePackage</goal>
</goals>
</execution>
</executions>
<configuration>
<jsSrcDir>src/main/javascript</jsSrcDir>
<jsTestSrcDir>src/test/javascript</jsTestSrcDir>
<preloadSources>
<preloadSource>lib/jquery-1.9.1.min.js</preloadSource>
</preloadSources>
</configuration>
</plugin>
I initially have one .js file called master.js. As you can see, it requires preloading jquery-1.9.1.min.js
or I get 'BUILD FAILED'. When I execute mvn compile
from terminal it checks the file and creates an obfuscated master.min.js file (with no errors) - I am also using yuicompressor-maven-plugin
.
Now I need to add more files to the project. The master.js is around 400 lines long and is required on every page of my project. The other files to add are large, sometimes over 1000 lines (but with lots of comments and documentation), and are specific to certain pages. For example, one is only required for logging in, whilst others are for admin purposes only.
Is there a way I can add these files to the maven build, with a dependancy (or preloading) my master.js file. The reason for doing this is;
- There are global variables and methods which are called/used from the other js pages (Don't worry, the variables and methods are not obfuscated)
- I do not wish to have duplicate code anywhere.
- I could create one very long file which would be fine, however;
- This would likely effect loading times.
- It is much harder to manage the code. (Perhaps the individual files can be merged when compiled)
If anyone has any thoughts or suggestions on this topic it would be really useful as I hope to follow the best practises and not stumble upon complications in the future.