Installation
The package offers a schematics to install the package and add the needed file changes in your spartacus project.
Schematics installation
Run the angular schematics
ng add @valantic/spartacus-mock
to install the package, add all needed changes and generate the boilerplate files.Check all the file changes made by the schematics, restore potential previous custom changes, as the adjusted files where copied from spartacus-mock
Optional: If you use PWA functionality, enhance your
ngsw-config.json
sectionapp
configfiles
array with"!/*mock*.js"
. This makes sure, the service worker does not load the mock server files.Optional: if you use prettier, add the file
src/mockServiceWorker.js
to the.prettierignore
file
Manual installation
Open a terminal and navigate to the root folder of your angular / spartacus project (the folder where the
angular.json
is located)Run
npm i @valantic/spartacus-mock@3.1.0 -d
to install the package as devDependencyRun
npm i msw@2.2.3 -d
to install the package as devDependencyEnhance
angular.json
architect build target assets array with"src/mockServiceWorker.js"
Enhanced
package.json
with the following object in the root levelEnhance your
src/environments/environment.ts
file with the following properties (these properties are needed for the mock server to work)mockServer: true,
with the following object in the root level
Add an
src/environments/environment.model.ts
to have better type safetyReplace the content of the file
src/main.ts
with the following content:Merge potential previous custom changes with the above content, if you have any
Optional: Run the schematics
ng boilerplate @valantic/spartacus-mock
and check the boilerplate files generated in thesrc/mock-server
folder for an easier startsrc/mock-server/index.ts
src/mock-server/routes.ts
src/mock-server/handlers.ts
src/mock-server/pass-through.ts
src/mock-server/mock-data/languages/languages.ts
Optional: If you use PWA functionality, enhance your
ngsw-config.json
app
configfiles
array with"!/*mock*.js"
. This makes sure, the service worker does not load the mock server files.
Last updated