1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = loader;
|
7 | exports.raw = void 0;
|
8 |
|
9 | var _path = _interopRequireDefault(require("path"));
|
10 |
|
11 | var _loaderUtils = _interopRequireDefault(require("loader-utils"));
|
12 |
|
13 | var _schemaUtils = _interopRequireDefault(require("schema-utils"));
|
14 |
|
15 | var _options = _interopRequireDefault(require("./options.json"));
|
16 |
|
17 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18 |
|
19 | function loader(content) {
|
20 | const options = _loaderUtils.default.getOptions(this) || {};
|
21 | (0, _schemaUtils.default)(_options.default, options, {
|
22 | name: 'File Loader',
|
23 | baseDataPath: 'options'
|
24 | });
|
25 | const context = options.context || this.rootContext;
|
26 |
|
27 | const url = _loaderUtils.default.interpolateName(this, options.name || '[contenthash].[ext]', {
|
28 | context,
|
29 | content,
|
30 | regExp: options.regExp
|
31 | });
|
32 |
|
33 | let outputPath = url;
|
34 |
|
35 | if (options.outputPath) {
|
36 | if (typeof options.outputPath === 'function') {
|
37 | outputPath = options.outputPath(url, this.resourcePath, context);
|
38 | } else {
|
39 | outputPath = _path.default.posix.join(options.outputPath, url);
|
40 | }
|
41 | }
|
42 |
|
43 | let publicPath = `__webpack_public_path__ + ${JSON.stringify(outputPath)}`;
|
44 |
|
45 | if (options.publicPath) {
|
46 | if (typeof options.publicPath === 'function') {
|
47 | publicPath = options.publicPath(url, this.resourcePath, context);
|
48 | } else {
|
49 | publicPath = `${options.publicPath.endsWith('/') ? options.publicPath : `${options.publicPath}/`}${url}`;
|
50 | }
|
51 |
|
52 | publicPath = JSON.stringify(publicPath);
|
53 | }
|
54 |
|
55 | if (options.postTransformPublicPath) {
|
56 | publicPath = options.postTransformPublicPath(publicPath);
|
57 | }
|
58 |
|
59 | if (typeof options.emitFile === 'undefined' || options.emitFile) {
|
60 | this.emitFile(outputPath, content);
|
61 | }
|
62 |
|
63 | const esModule = typeof options.esModule !== 'undefined' ? options.esModule : true;
|
64 | return `${esModule ? 'export default' : 'module.exports ='} ${publicPath};`;
|
65 | }
|
66 |
|
67 | const raw = true;
|
68 | exports.raw = raw; |
\ | No newline at end of file |