UNPKG

848 BJavaScriptView Raw
1const Asset = require('../Asset');
2const urlJoin = require('../utils/urlJoin');
3const md5 = require('../utils/md5');
4
5class RawAsset extends Asset {
6 // Don't load raw assets. They will be copied by the RawPackager directly.
7 load() {}
8
9 generate() {
10 // Don't return a URL to the JS bundle if there is a bundle loader defined for this asset type.
11 // This will cause the actual asset to be automatically preloaded prior to the JS bundle running.
12 if (this.options.bundleLoaders[this.type]) {
13 return {};
14 }
15
16 const pathToAsset = urlJoin(
17 this.options.publicURL,
18 this.generateBundleName()
19 );
20
21 return [
22 {
23 type: 'js',
24 value: `module.exports=${JSON.stringify(pathToAsset)};`
25 }
26 ];
27 }
28
29 async generateHash() {
30 return md5.file(this.name);
31 }
32}
33
34module.exports = RawAsset;