CCv2 build and deploy with Spartacus 2.0
See original GitHub issueCustomers who try to run Spartacus 2 based Applications to ccv2 face build and deploy issues. Investigations are in progress, but we’re getting already some clues about the issue.
The fundamental issue is related to a changing file layout from angular 8 to 9. Spartacus 2 moved to Angular 9, and with this, customers would likely receive the standard angular 9 based file layout after building.
The angular 8 based file layout contains a dist folder with all the application build files in a subfolder. The SSR entry file (server.js
) has been stored in the dist folder.
(note: the main.js
in the test-app-server is an intermediate build file and not used in ccv2 build/deploy).
The difference in the angular 9 based applications is that the client rendering and server rendering are separated in two named folders.
A couple of important changes:
- The
server.ts
file has moved to the nested server folder - The
index.html
has moved to the nested browser folder
The different file layout is quite likely the root cause.
To be verified
- It seems that the ccv2 build/deploy is copying the
index.html
to a location. Given that the underlying file structured changed, we seem to have a misalignment. - ~We don’t know if~ this is also causing issue for non-SSR deployments
- The solution should be backwards compatible, ~moreover we’re not yet sure if recent changes affect the 1.5 releases~.
- ~a quick code analysis of the ccv2 build process shows that the occ placeholder meta tag does not get replaced correctly~.
Potential Solution Directions
- change the angular build process to adapt the current expected file layout (this could be quick win for current customers)
- ~introduce a schematics to fit the ccv2 general file layout~
- improve ccv2 to adapt both ng8 and ng9 file layout
- add properties to the manifest.json so that customers are more in control
- ~consider using package.json as an configurable script to start the application~
Issue Analytics
- State:
- Created 3 years ago
- Comments:26 (9 by maintainers)
Yes @arelsirin , it should work and it’s now a recommended workaround as fixing it in CCV2 might be delayed because of various reasons.
One way to make it automated, is for example to adding
&& mv dist/app-folder-server/main.js dist/server.js || move dist\\app-folder-server\\main.js dist\\server.js",
tobuild:ssr
command inpackage.json
.As initially discussed with ccv2 team members, we would like to make
manifest.json
more configurable, to accommodate more specific cases (and keep backward compatibility with current solutions). Also, for now, the best approach is to adapt Angular build process to match the expected layout, which means:angular.json
"outputPath": "dist/app-name/browser"
, to"outputPath": "dist/app-name",
"outputPath": "dist/app-name/server"
, tp"outputPath": "dist/app-name-server",
server,ts
:const distFolder = join(process.cwd(), 'dist/app-name/browser');
toconst distFolder = join(process.cwd(), 'dist/app-name');