当前位置: 首页 > 软件库 > 程序开发 > >

ember-asset-loader

Asset loading support for Ember applications
授权协议 MIT License
开发语言 JavaScript
所属分类 程序开发
软件类型 开源软件
地区 不详
投 递 者 潘琨
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Ember Asset Loader

Code Climate

Provides experimental support for the Asset Manifest RFC and Asset Loader Service RFC.

Usage

Ember Asset Loader does three primary things:

  1. Provides a base class to easily generate an Asset Manifest,
  2. Provides an Ember service to use the generated manifest at runtime, and
  3. Initializes the above service with the above generated manifest.

Generating an Asset Manifest

You can generate an Asset Manifest by creating either a standalone or in-repo addon which extends from theManifestGenerator base class:

var ManifestGenerator = require('ember-asset-loader/lib/manifest-generator');
module.exports = ManifestGenerator.extend({
  name: 'asset-generator-addon',
  manifestOptions: {
    bundlesLocation: 'engines-dist',
    supportedTypes: [ 'js', 'css' ]
  }
});

The ManifestGenerator will generate an asset manifest and merge it into your build tree during post-processing. Itgenerates the manifest according to the options specified in manifestOptions:

  • The bundlesLocation option is a string that specifies which directory in the build tree contains the bundles to beplaced into the asset manifest. This defaults to bundles. Each bundle is a directory containing files that will be downloaded when the bundle is requested. You are responsible for getting the right files into those directories.

  • The supportedTypes option is an array that specifies which types of files should be included into the bundles forthe asset manifest. This defaults to [ 'js', 'css' ].

Note: This class provides default contentFor, postprocessTree, and postBuild hooks so be sure that you call_super if you override one of those methods.

Why isn't a manifest generated by default?

This addon doesn't perform manifest generation just by virtue of being installed because there is no convention forbundling assets within Ember yet. Thus, to prevent introducing unintuitive or conflicting behavior, we provide nodefault generation and you must perform asset generation in your own addon using the base class provided by this addon.

If no manifest is generated, you'll get a warning at build time to ensure that you understand no manifest has beengenerated and thus you'll have to provide a manifest manually in order to use the Asset Loader Service. This warning canbe disabled via the noManifest option from the consuming application:

var app = new EmberApp(defaults, {
  assetLoader: {
    noManifest: true
  }
});

Generating Custom URIs

Custom URIs are often needed due to serving assets from CDNs or another server that does not share the same rootlocation as your application. Instead of having to write a custom Broccoli plugin or other build-time transform, you canspecify a generateURI function as part of your application's options:

var app = new EmberApp(defaults, {
  assetLoader: {
    generateURI: function(filePath) {
      return 'http://cdn.io/' + filePath;
    }
  }
});

The function receives the filePath for each asset and must return a string.

Ignore Files

To ignore specific files during the manifest generation, use filesToIgnore.Both string and regex patterns are accepted.

var app = new EmberApp(defaults, {
  assetLoader: {
    filesToIgnore: [/foo-engine/**/engine-vendor.js$/, 'vendor.js']
  }
});

Using With broccoli-asset-rev

You need to make sure that broccoli-asset-rev runs after your ManifestGenerator addon runs. Here is an example of how to do that:

  1. Create an in-repo-addon: ember generate in-repo-addon asset-generator-addon

  2. Make it generate the manifest by editing lib/asset-generator-addon/index.js as described under "Generating an Asset Manifest" above.

  3. Edit lib/asset-generator-addon/package.json to configure the addon to run after broccoli-asset-rev

{
  "name": "asset-generator-addon",
  "keywords": [
    "ember-addon"
  ],
  "ember-addon": {
    "after": "broccoli-asset-rev"
  }
}

Usage with FastBoot / Server-Side Rendering Solutions

Using lazily loaded assets with a server-side rendering solution, such as FastBoot, is often desirable to maximizeperformance for your consumers. However, lazy loading assets on your server is not the same as on the client andcan actually have negative performance impact. Due to that, the recommendation is to pre-load all your assets in theserver.

Additionally, at build time we will generate an assets/node-asset-manifest.js file that should be included in your SSRenvironment to ensure that your application can correctly access asset information.

See the "How to handle running in Node" issue for moreinformation.

Pre-loading Assets During Testing

For test environments it is often useful to load all of the assets in a manifest upfront. You can do this by using thepreloadAssets helper, like so:

// tests/test-helper.js
import preloadAssets from 'ember-asset-loader/test-support/preload-assets';
import manifest from 'app/config/asset-manifest';

preloadAssets(manifest);

Resetting Test State

When testing applications with lazy assets, it is important to reset the state of those assets in between tests. To dothis, Ember Asset Loader provides two helpers: cacheLoadedAssetState() and resetLoadedAssetState().

// tests/test-helper.js
import preloadAssets from 'ember-asset-loader/test-support/preload-assets';
import { cacheLoadedAssetState, resetLoadedAssetState } from 'ember-asset-loader/test-support/loaded-asset-state';
import manifest from 'app/config/asset-manifest';

cacheLoadedAssetState();
preloadAssets(manifest).then(() => {
  resetLoadedAssetState(); // Undoes the previous load!
});

It is important to note that resetLoadedAssetState can only remove additional scripts, stylesheets, and modules loadedsince cacheLoadedAssetState was called. If any of the loaded assets modified global state, we'll be unable to restorethat state. Therefore, it is important to keep your lazy assets encapsulated and make sure they don't modified any statealready in the browser.

Note: If you use QUnit, it may be worthwhile to turn on the noglobals config option,to help catch mutated global state.

Installation

  • git clone https://github.com/ember-engines/ember-asset-loader
  • cd ember-asset-loader
  • npm install
  • bower install

Running

Running Tests

One of three options:

  • npm test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://ember-cli.com/.

 相关资料
  • Asset Pipeline 本文介绍 Asset Pipeline。 读完本文,你将学到: Asset Pipeline 是什么以及其作用; 如何合理组织程序的静态资源; Asset Pipeline 的优势; 如何向 Asset Pipeline 中添加预处理器; 如何在 gem 中打包静态资源; 1 Asset Pipeline 是什么? Asset Pipeline 提供了一个框架,用于连

  • Asset Packagist Composer + Bower + NPM = friends forever! This package is the core part of https://asset-packagist.org/ project. Asset Packagist allows installation of Bower and NPM packages as native

  • AspNet.Mvc.AssetVersioning Adds a UrlHelper.VersionedContent URL extension helper to append SHA256 hash to content URLs in ASP.NET MVC 5. Install Install-Package AspNet.Mvc.AssetVersioning Usage In Vi

  • NPM/Bower Dependency Manager for Composer The Composer Asset Plugin allows you to manage project assets (css, js, etc.) in your composer.jsonwithout installing NPM or Bower. This plugin works by trans

  • pwa-asset-generator ✨ Automates PWA asset generation and image declaration. Automatically generates icon and splash screen images, favicons and mstile images. Updates manifest.json and index.html file

  • Hexo 本地图片插件可以转换图片相对路径 为 asset_img,使用本插件即可实现 Typora 等 Markdown 编辑器预览与 Hexo 发布预览均能正常显示图片。 使用 npm install hexo-asset-img --save hexo-typora├── apppicker.jpg├── logo.png└── rules.jpghexo-typora.md Make su