{"id":18320858,"url":"https://github.com/bazaarvoice/static-asset-service","last_synced_at":"2025-04-05T22:32:04.250Z","repository":{"id":32453325,"uuid":"36032694","full_name":"bazaarvoice/static-asset-service","owner":"bazaarvoice","description":"An optimization service for web application static assets.","archived":false,"fork":false,"pushed_at":"2020-09-16T17:52:52.000Z","size":238,"stargazers_count":0,"open_issues_count":0,"forks_count":8,"subscribers_count":32,"default_branch":"master","last_synced_at":"2024-09-26T09:38:16.062Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"sclorg/ruby-ex","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bazaarvoice.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-21T19:19:42.000Z","updated_at":"2020-09-16T17:52:55.000Z","dependencies_parsed_at":"2022-07-12T11:00:42.763Z","dependency_job_id":null,"html_url":"https://github.com/bazaarvoice/static-asset-service","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazaarvoice%2Fstatic-asset-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazaarvoice%2Fstatic-asset-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazaarvoice%2Fstatic-asset-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazaarvoice%2Fstatic-asset-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bazaarvoice","download_url":"https://codeload.github.com/bazaarvoice/static-asset-service/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223221181,"owners_count":17108525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T18:17:40.147Z","updated_at":"2024-11-05T18:17:40.815Z","avatar_url":"https://github.com/bazaarvoice.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Static Asset Service\n\nThis repository provides tools to generate and upload to S3 the asset files used\nby a static asset service. Such a service can be used by client applications to\nshare Javascript assets in an organized, declarative way, and thus reduce the\noverall page size and number of requests when multiple applications coexist on\nthe same page.\n\n## Overview\n\nThis repository provides the tools for generating combined and compiled asset\nfiles from base assets, and then deploying the files to S3 so that they can be\nconsumed by applications using the [static asset loader client][1].\n\nThe [example Assets](./example-assets) illustrate the form required for assets\nthat the service provides.\n\nThe [static asset client][1] used to require and define assets in a Javascript\nclient application is not included in this repository, but is rather a part of\n[bv-ui-core][2].\n\n## Generating Static Asset Files\n\nTo generate the asset files:\n\n```js\nvar staticAssetService = require('static-asset-service');\n\nstaticAssetService.generate({\n  // The namespace that apps consuming these generated assets will use.\n  namespaceName: 'BV',\n\n  // The directory where the generator can expect to find the asset files.\n  sourceDir: '/path/to/assets',\n\n  // The destination where the assets will be created.\n  targetDir: '/path/to/dist',\n\n  // If true, minify the generated outputs using uglify.\n  uglify: true,\n\n  // If true, log progress to the console.\n  log: true,\n\n  // List the asset bundles that need to be supported for each application using\n  // this service. The generator will only generate combination files for these\n  // listed assets.\n  //\n  // We constrain the asset generation in this way for combinatorial reasons -\n  // creating static combinations gets large rapidly. Ten assets combine to\n  // more than 1000 files even with alphanumeric ordering of names enforced, but\n  // four or less is managable.\n  //\n  // Each asset must have a corresponding file in the assets directory. For\n  // example, for the asset jquery-example@1.11.1, there must be a file\n  // assets/jquery-example/1.11.1.js.\n  //\n  // IMPORTANT: assets MUST be listed in dependency order, i.e. the order in\n  // which they must load to satisfy one another.\n  assetBundles: {\n    firebird: [\n      'jquery-example@1.11.1',\n      'lodash-example@1.2.0',\n      'backbone-example@1.0.0'\n    ],\n    curations: [\n      'jquery-example@1.11.1',\n      'underscore@1.5.2'\n    ],\n    spotlights: [\n      'lodash@2.4.1',\n      'backbone-example@1.2.0'\n    ]\n  }\n}, function (error) {\n  if (error) {\n    console.error('Generation failed.', error);\n  }\n  else {\n    console.info('Generation complete.');\n  }\n});\n```\n\n### About the Namespace\n\nThe static asset service requires a global namespace - that is, a property on\n`window` - that it can use to communicate back to the apps that request assets.\nWhen generating files, this namespace needs to be known in order to properly\nprovide the individual assets to the requesting application.\n\nIn browser applications, the namespace is generated by the\n[bv-ui-core namespacer][3] module.\n\n## Uploading Generated Files to S3\n\nTo upload the generated asset files to an S3 bucket:\n\n```js\nvar staticAssetService = require('static-asset-service');\n\nstaticAssetService.deployToS3({\n  // Upload assets to this S3 bucket.\n  bucket: 'example',\n\n  // The prefix put in place for the keys of the uploaded files.\n  keyPrefix: 'example/assets/'\n\n  // If true, log progress to the console.\n  log: true,\n\n  // Optionally, specify configuration for the aws-sdk client instance. This is\n  // not recommended. For preference configure S3 access using the other options\n  // that do not require configuration changes in code: environment variables,\n  // EC2 instance roles, etc.\n  // s3ClientConfig: {\n  //   accessKeyId: 'akid',\n  //   secretAccessKey: 'secret',\n  //   region: 'us-east-1'\n  // },\n\n  // The absolute path to the generated asset files.\n  sourceDir: '/path/to/dist',\n\n  // A semver version for your assets. Assets will be uploaded to multiple\n  // locations in the bucket determined by the version and keyPrefix:\n  //\n  // example/assets/1\n  // example/assets/1.0\n  // example/assets/1.0.0\n  version: '1.0.0'\n}, function (error) {\n  if (error) {\n    console.error('Deployment failed.', error);\n  }\n  else {\n    console.info('Deployment complete.');\n  }\n});\n```\n\n## Creating Asset Files\n\n### Example Assets\n\nThe `example-assets` directory contains a selection of example assets that could\nbe provided by a static asset service. The file names and contents have a few\nrestrictions, outlined here.\n\n### File Names\n\nAsset files must have names in the format: `\u003cresource\u003e@\u003cversion\u003e.js`.\n\n### File Contents\n\nAsset files should contain valid JavaScript, structured as follows so that the\n`define` function is invoked as `define(assetName, asset)`. The asset code is\nwrapped in a closure to ensure that different versions can be loaded and used if\nnecessary.\n\n```js\ndefine('\u003cresource\u003e@\u003cversion\u003e', (function () {\n\n  // ...\n\n  return resource;\n})());\n```\n\n## Development\n\n### Getting Started\n\nDevelopers should run `npm install` before doing any work on this repository.\nThis will install the project dependencies, as well as a pre-push hook.\n\n### Running the Tests\n\n`grunt test` will run the browser tests using PhantomJS, as well as ESLint and\nthe tests of the generator code.\n\n`grunt serve` will open a browser to show the browser tests.\n\n[1]: https://github.com/bazaarvoice/bv-ui-core/tree/master/lib/staticAssetLoader\n[2]: https://github.com/bazaarvoice/bv-ui-core\n[3]: https://github.com/bazaarvoice/bv-ui-core/tree/master/lib/namespacer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbazaarvoice%2Fstatic-asset-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbazaarvoice%2Fstatic-asset-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbazaarvoice%2Fstatic-asset-service/lists"}