Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally allow assets to be loaded without a manifest. Update README to document available options. #89

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ the 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._

### Options

##### noManifest

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the default value?

* Type: `boolean`
* Default: `undefined`
* If `true`, a <meta> tag which would eventually hold the manifest will not be inserted into the DOM.

##### noManifestLookup

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the flag actually not lookup the manifest? Or is it just going to ignore any errors arising from a lookup? What is the default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If noManifestLookup is set to true, then there will be no manifest lookup. The default value will be undefined, meaning the manifest will be looked up by default (backwards compatible)

* Type: `boolean`
* Default: `undefined`
* If `true`, no error will be thrown in the event that a manifest was not generated for the current environment

### 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 for
Expand Down
27 changes: 16 additions & 11 deletions app/config/asset-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ const metaName = `${modulePrefix}/config/asset-manifest`;
const nodeName = `${modulePrefix}/config/node-asset-manifest`;

let config = {};
const lookupManifest = !environment.noManifestLookup;

try {
// If we have a Node version of the asset manifest, use that for FastBoot and
// similar environments.
if (require.has(nodeName)) {
config = require(nodeName).default; // eslint-disable-line
} else {
const rawConfig = document.querySelector('meta[name="' + metaName + '"]').getAttribute('content');
config = JSON.parse(unescape(rawConfig));
if (lookupManifest) {
try {
// If we have a Node version of the asset manifest, use that for FastBoot and
// similar environments.
if (require.has(nodeName)) {
config = require(nodeName).default; // eslint-disable-line
} else {
const rawConfig = document.querySelector('meta[name="' + metaName + '"]').getAttribute('content');
config = JSON.parse(unescape(rawConfig));
}
} catch(err) {
throw new Error('No manifest was found with the name "' + metaName +
'". To hide this message you can set the config option `noManifestLookup` to `true`. For non-browser environments, verify that you included the node-asset-manifest module.', {
id: 'no-manifest-found'
});
}
} catch(err) {
throw new Error('Failed to load asset manifest. For browser environments, verify the meta tag with name "'+ metaName +
'" is present. For non-browser environments, verify that you included the node-asset-manifest module.');
}

export default config;