1+ ## Install npm Locally
2+
3+ ```
4+ <build>
5+ <plugins>
6+ <plugin>
7+ <groupId>org.springframework.boot</groupId>
8+ <artifactId>spring-boot-maven-plugin</artifactId>
9+ </plugin>
10+ <plugin>
11+ <groupId>com.github.eirslett</groupId>
12+ <artifactId>frontend-maven-plugin</artifactId>
13+ <version>1.6</version>
14+ <configuration>
15+ <nodeVersion>v8.8.1</nodeVersion>
16+ </configuration>
17+ <executions>
18+ <execution>
19+ <id>install-npm</id>
20+ <goals>
21+ <goal>install-node-and-npm</goal>
22+ </goals>
23+ </execution>
24+ </executions>
25+ </plugin>
26+ <plugin>
27+ <groupId>org.springframework.boot</groupId>
28+ <artifactId>spring-boot-maven-plugin</artifactId>
29+ </plugin>
30+ </plugins>
31+ </build>
32+ ```
33+
34+ then
35+
136```
2- <build>
3- <plugins>
4- <plugin>
5- <groupId>org.springframework.boot</groupId>
6- <artifactId>spring-boot-maven-plugin</artifactId>
7- </plugin>
8- <plugin>
9- <groupId>com.github.eirslett</groupId>
10- <artifactId>frontend-maven-plugin</artifactId>
11- <version>1.6</version>
12- <configuration>
13- <nodeVersion>v8.8.1</nodeVersion>
14- </configuration>
15- <executions>
16- <execution>
17- <id>install-npm</id>
18- <goals>
19- <goal>install-node-and-npm</goal>
20- </goals>
21- </execution>
22- </executions>
23- </plugin>
24- <plugin>
25- <groupId>org.springframework.boot</groupId>
26- <artifactId>spring-boot-maven-plugin</artifactId>
27- </plugin>
28- </plugins>
29- </build>
37+ $ mvn generate-resources
38+ $ ls node*
3039```
3140
41+ ## Install Angular CLI
42+
3243```
33- $ mvn generate-resources
3444$ cat > npm
3545#!/bin/sh
46+ cd $(dirname $0)
3647PATH="$PWD/node/":$PATH
3748node "node/node_modules/npm/bin/npm-cli.js" "$@"
3849$ chmod +x npm
@@ -44,22 +55,25 @@ and run `mvn generate-resources` again.
4455```
4556$ cat > ng
4657#!/bin/sh
58+ cd $(dirname $0)
4759PATH="$PWD/node/":$PATH
4860node_modules/@angular/cli/bin/ng "$@"
4961$ chmod +x ng
5062$ ./ng --version
51- _ _ ____ _ ___
63+ _ _ ____ _ ___
5264 / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
5365 / △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
5466 / ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
5567/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
56- |___/
68+ |___/
5769@angular/cli: 1.4.9
5870node: 8.8.1
5971os: linux x64
6072```
6173
62- Now create an angular app:
74+ ## Create an Angular App
75+
76+ Create the app with the CLI and move it to ` src/main ` :
6377
6478```
6579$ ./ng new client
@@ -69,38 +83,40 @@ $ sed -i -e 's,dist,../../../target/classes/static,' src/main/client/.angular-cl
6983$ mv ng npm src/main/client
7084```
7185
86+ ## Building
87+
7288Add
7389
7490```
75- <configuration>
76- <workingDirectory>src/main/client</workingDirectory>
77- </configuration>
91+ <configuration>
92+ <workingDirectory>src/main/client</workingDirectory>
93+ </configuration>
7894```
7995
8096and
8197
8298```
83- <execution>
84- <id>npm-install</id>
85- <goals>
86- <goal>npm</goal>
87- </goals>
88- <configuration>
89- <arguments>install</arguments>
90- </configuration>
91- </execution>
99+ <execution>
100+ <id>npm-install</id>
101+ <goals>
102+ <goal>npm</goal>
103+ </goals>
104+ <configuration>
105+ <arguments>install</arguments>
106+ </configuration>
107+ </execution>
92108```
93109
94110Install the modules again using ` mvn generate-resources ` .
95111
96112```
97- $ (cd src/main/client; . /ng version)
98- _ _ ____ _ ___
113+ $ src/main/client/ng version
114+ _ _ ____ _ ___
99115 / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
100116 / △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
101117 / ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
102118/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
103- |___/
119+ |___/
104120@angular/cli: 1.4.9
105121node: 8.8.1
106122os: linux x64
@@ -122,13 +138,13 @@ typescript: 2.3.4
122138And the tests work:
123139
124140```
125- $ (cd src/main/client; . /ng e2e.)
141+ $ src/main/client/ng e2e
126142..
127143[13:59:46] I/direct - Using ChromeDriver directly...
128144Jasmine started
129145
130146 client App
131- ✓ should display welcome message
147+ ✓ should display welcome message
132148
133149Executed 1 of 1 spec SUCCESS in 0.718 sec.
134150[13:59:48] I/launcher - 0 instance(s) of WebDriver still running
@@ -138,36 +154,44 @@ Executed 1 of 1 spec SUCCESS in 0.718 sec.
138154Add
139155
140156```
141- <execution>
142- <id>npm-build</id>
143- <goals>
144- <goal>npm</goal>
145- </goals>
146- <configuration>
147- <arguments>run-script build</arguments>
148- </configuration>
149- </execution>
150-
157+ <execution>
158+ <id>npm-build</id>
159+ <goals>
160+ <goal>npm</goal>
161+ </goals>
162+ <configuration>
163+ <arguments>run-script build</arguments>
164+ </configuration>
165+ </execution>
151166```
152167
153168and then the client app will be compiled during the Maven build.
154169
170+ You can build continuously with
171+
172+ ```
173+ $ src/main/client/ng build --watch
174+ ```
175+
176+ Updates are built (quickly) and pushed to ` target/classes ` where they can be picked up by Spring Boot.
177+
178+ ## Adding Bootstrap
179+
155180https://medium.com/codingthesmartway-com-blog/using-bootstrap-with-angular-c83c3cee3f4a
156181
157182```
158- $ cd src/main/client
159- $ ./npm install bootstrap@3 jquery --save
183+ $ src/main/client/npm install bootstrap@3 jquery --save
160184```
161185
162186and update ` .angular-cli.json ` to add the new content:
163187
164188```
165189 "styles": [
166- "styles.css",
167- "../node_modules/bootstrap/dist/css/bootstrap.min.css"
190+ "styles.css",
191+ "../node_modules/bootstrap/dist/css/bootstrap.min.css"
168192 ],
169193 "scripts": [
170- "../node_modules/jquery/dist/jquery.min.js",
171- "../node_modules/bootstrap/dist/js/bootstrap.min.js"
194+ "../node_modules/jquery/dist/jquery.min.js",
195+ "../node_modules/bootstrap/dist/js/bootstrap.min.js"
172196 ],
173197```
0 commit comments