This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #602 from zarathustra323/4.x_asset-and-test-tweaks
Replace asset manager with dist loader; enhance in-body error tests
- Loading branch information
Showing
8 changed files
with
60 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const path = require('path'); | ||
const { readFileSync } = require('fs'); | ||
|
||
const loadFromManifest = ({ distDir, type, entry }) => { | ||
const file = path.resolve(distDir, type, 'manifest.json'); | ||
const json = readFileSync(file, { encoding: 'utf8' }); | ||
const manifest = JSON.parse(json); | ||
const asset = manifest[entry]; | ||
if (!asset) throw new Error(`Unable to extract an asset for type ${type} using manifest entry ${entry}`); | ||
return `/dist/${type}/${asset.file}`; | ||
}; | ||
|
||
module.exports = ({ distDir, type, entry }) => { | ||
let file; | ||
const isDevelopment = process.env.NODE_ENV !== 'production'; | ||
return () => { | ||
// when on dev, always return the file from the manifest | ||
// as it may have changed during build. | ||
if (isDevelopment) return loadFromManifest({ distDir, type, entry }); | ||
// otherwise, only retrieve it once | ||
if (!file) file = loadFromManifest({ distDir, type, entry }); | ||
return file; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters