UNPKG

1.1 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
6
7const Asset = require('../Asset');
8
9const urlJoin = require('../utils/urlJoin');
10
11const md5 = require('../utils/md5');
12
13class RawAsset extends Asset {
14 // Don't load raw assets. They will be copied by the RawPackager directly.
15 load() {}
16
17 generate() {
18 // Don't return a URL to the JS bundle if there is a bundle loader defined for this asset type.
19 // This will cause the actual asset to be automatically preloaded prior to the JS bundle running.
20 if (this.options.bundleLoaders[this.type]) {
21 return {};
22 }
23
24 const pathToAsset = urlJoin(this.options.publicURL, this.generateBundleName());
25 return [{
26 type: 'js',
27 value: `module.exports=${JSON.stringify(pathToAsset)};`
28 }];
29 }
30
31 generateHash() {
32 var _this = this;
33
34 return (0, _asyncToGenerator2.default)(function* () {
35 return md5.file(_this.name);
36 })();
37 }
38
39}
40
41module.exports = RawAsset;
\No newline at end of file