可以採用StackBlitz WebIDE線上建立:
也可以採用Angular cli建立,命令列如下:
> ng new mystore --style=scss
然後使用Spartacus schematics自動新增依賴:
開啟app.module.ts, 替換B2cStorefrontModule.withConfig方法內的配置為實際的Commerce Cloud後臺:
import { BrowserModule } from '@angular/platform-browser';import { NgModule } from '@angular/core';import { AppComponent } from './app.component';import { translations, translationChunksConfig } from '@spartacus/assets';import { B2cStorefrontModule } from '@spartacus/storefront';@NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, B2cStorefrontModule.withConfig({ backend: { occ: { baseUrl: 'https://spartacus-jerry.eastus.cloudapp.azure.com:9002', prefix: '/occ/v2/' } }, context: { currency: ['USD'], language: ['en'], baseSite: ['electronics-spa'] }, i18n: { resources: translations, chunks: translationChunksConfig, fallbackLang: 'en' }, features: { level: '2.1' } }) ], providers: [], bootstrap: [AppComponent]})export class AppModule { }
之後即可正常工作: