Provides experimental support for the Asset Manifest RFC and Asset Loader Service RFC.
Ember Asset Loader does three primary things:
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.
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
}
});
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.
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']
}
});
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:
Create an in-repo-addon: ember generate in-repo-addon asset-generator-addon
Make it generate the manifest by editing lib/asset-generator-addon/index.js
as described under "Generating an Asset Manifest" above.
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"
}
}
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.
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);
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.
git clone https://github.com/ember-engines/ember-asset-loader
cd ember-asset-loader
npm install
bower install
ember serve
One of three options:
npm test
(Runs ember try:each
to test your addon against multiple Ember versions)ember test
ember test --server
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