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, 'File Loader');
|
22 | const context = options.context || this.rootContext;
|
23 |
|
24 | const url = _loaderUtils.default.interpolateName(this, options.name, {
|
25 | context,
|
26 | content,
|
27 | regExp: options.regExp
|
28 | });
|
29 |
|
30 | let outputPath = url;
|
31 |
|
32 | if (options.outputPath) {
|
33 | if (typeof options.outputPath === 'function') {
|
34 | outputPath = options.outputPath(url, this.resourcePath, context);
|
35 | } else {
|
36 | outputPath = _path.default.posix.join(options.outputPath, url);
|
37 | }
|
38 | }
|
39 |
|
40 | let publicPath = `__webpack_public_path__ + ${JSON.stringify(outputPath)}`;
|
41 |
|
42 | if (options.publicPath) {
|
43 | if (typeof options.publicPath === 'function') {
|
44 | publicPath = options.publicPath(url, this.resourcePath, context);
|
45 | } else {
|
46 | publicPath = `${options.publicPath.endsWith('/') ? options.publicPath : `${options.publicPath}/`}${url}`;
|
47 | }
|
48 |
|
49 | publicPath = JSON.stringify(publicPath);
|
50 | }
|
51 |
|
52 | if (typeof options.emitFile === 'undefined' || options.emitFile) {
|
53 | this.emitFile(outputPath, content);
|
54 | }
|
55 |
|
56 |
|
57 | return `module.exports = ${publicPath};`;
|
58 | }
|
59 |
|
60 | const raw = true;
|
61 | exports.raw = raw; |
\ | No newline at end of file |