diff --git a/cmd/project/ci.go b/cmd/project/ci.go index 3d24d8e5..37cd3d3c 100644 --- a/cmd/project/ci.go +++ b/cmd/project/ci.go @@ -79,6 +79,7 @@ var projectCI = &cobra.Command{ CleanupNodeModules: true, ShopwareRoot: args[0], ShopwareVersion: constraint, + Browserslist: shopCfg.Build.Browserslist, } if err := extension.BuildAssetsForExtensions(cmd.Context(), sources, assetCfg); err != nil { diff --git a/extension/asset_platform.go b/extension/asset_platform.go index 832dc3cb..ceadf444 100644 --- a/extension/asset_platform.go +++ b/extension/asset_platform.go @@ -34,6 +34,7 @@ type AssetBuildConfig struct { DisableStorefrontBuild bool ShopwareRoot string ShopwareVersion *version.Constraints + Browserslist string } func BuildAssetsForExtensions(ctx context.Context, sources []asset.Source, assetConfig AssetBuildConfig) error { // nolint:gocyclo @@ -113,7 +114,6 @@ func BuildAssetsForExtensions(ctx context.Context, sources []asset.Source, asset continue } - // @todo: fix me later options := esbuild.NewAssetCompileOptionsAdmin(source.Name, source.Path) if _, err := esbuild.CompileExtensionAsset(ctx, options); err != nil { @@ -146,7 +146,6 @@ func BuildAssetsForExtensions(ctx context.Context, sources []asset.Source, asset continue } - // @todo: fix me later options := esbuild.NewAssetCompileOptionsStorefront(source.Name, source.Path) if _, err := esbuild.CompileExtensionAsset(ctx, options); err != nil { return err @@ -154,10 +153,29 @@ func BuildAssetsForExtensions(ctx context.Context, sources []asset.Source, asset } } else { storefrontRoot := PlatformPath(shopwareRoot, "Storefront", "Resources/app/storefront") + + envList := []string{ + fmt.Sprintf("PROJECT_ROOT=%s", shopwareRoot), + fmt.Sprintf("STOREFRONT_ROOT=%s", storefrontRoot), + } + + if assetConfig.Browserslist != "" { + npx := exec.CommandContext(ctx, "npx", "--yes", "update-browserslist-db", "--quiet") + npx.Stdout = os.Stdout + npx.Stderr = os.Stderr + npx.Dir = storefrontRoot + + if err := npx.Run(); err != nil { + return err + } + + envList = append(envList, fmt.Sprintf("BROWSERSLIST=%s", assetConfig.Browserslist)) + } + err := npmRunBuild( storefrontRoot, "production", - []string{fmt.Sprintf("PROJECT_ROOT=%s", shopwareRoot), fmt.Sprintf("STOREFRONT_ROOT=%s", storefrontRoot)}, + envList, ) if assetConfig.CleanupNodeModules { diff --git a/shop/config.go b/shop/config.go index bb9ce011..4a434a28 100644 --- a/shop/config.go +++ b/shop/config.go @@ -24,6 +24,7 @@ type ConfigBuild struct { RemoveExtensionAssets bool `yaml:"remove_extension_assets,omitempty"` KeepExtensionSource bool `yaml:"keep_extension_source,omitempty"` CleanupPaths []string `yaml:"cleanup_paths,omitempty"` + Browserslist string `yaml:"browserslist,omitempty"` } type ConfigAdminApi struct { diff --git a/shop/shopware-project-schema.json b/shop/shopware-project-schema.json index 96d83ad2..881bd87d 100644 --- a/shop/shopware-project-schema.json +++ b/shop/shopware-project-schema.json @@ -46,6 +46,10 @@ "type": "array", "items": {"type": "string"}, "description": "Paths to delete for the final build" + }, + "browserslist": { + "type": "string", + "description": "Browserslist configuration for the Storefront build" } } },