1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.raw = undefined;
|
7 | exports.default = loader;
|
8 |
|
9 | var _path = require('path');
|
10 |
|
11 | var _path2 = _interopRequireDefault(_path);
|
12 |
|
13 | var _loaderUtils = require('loader-utils');
|
14 |
|
15 | var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
|
16 |
|
17 | var _schemaUtils = require('schema-utils');
|
18 |
|
19 | var _schemaUtils2 = _interopRequireDefault(_schemaUtils);
|
20 |
|
21 | var _options = require('./options.json');
|
22 |
|
23 | var _options2 = _interopRequireDefault(_options);
|
24 |
|
25 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
26 |
|
27 | function loader(content) {
|
28 | if (!this.emitFile) throw new Error('File Loader\n\nemitFile is required from module system');
|
29 |
|
30 | var options = _loaderUtils2.default.getOptions(this) || {};
|
31 |
|
32 | (0, _schemaUtils2.default)(_options2.default, options, 'File Loader');
|
33 |
|
34 | var context = options.context || this.rootContext || this.options && this.options.context;
|
35 |
|
36 | var url = _loaderUtils2.default.interpolateName(this, options.name, {
|
37 | context,
|
38 | content,
|
39 | regExp: options.regExp
|
40 | });
|
41 |
|
42 | var outputPath = url;
|
43 |
|
44 | if (options.outputPath) {
|
45 | if (typeof options.outputPath === 'function') {
|
46 | outputPath = options.outputPath(url);
|
47 | } else {
|
48 | outputPath = _path2.default.posix.join(options.outputPath, url);
|
49 | }
|
50 | }
|
51 |
|
52 | if (options.useRelativePath) {
|
53 | var filePath = this.resourcePath;
|
54 |
|
55 | var issuerContext = context || this._module && this._module.issuer && this._module.issuer.context;
|
56 |
|
57 | var relativeUrl = issuerContext && _path2.default.relative(issuerContext, filePath).split(_path2.default.sep).join('/');
|
58 |
|
59 | var relativePath = relativeUrl && `${_path2.default.dirname(relativeUrl)}/`;
|
60 |
|
61 | if (~relativePath.indexOf('../')) {
|
62 | outputPath = _path2.default.posix.join(outputPath, relativePath, url);
|
63 | } else {
|
64 | outputPath = _path2.default.posix.join(relativePath, url);
|
65 | }
|
66 | }
|
67 |
|
68 | var publicPath = `__webpack_public_path__ + ${JSON.stringify(outputPath)}`;
|
69 |
|
70 | if (options.publicPath) {
|
71 | if (typeof options.publicPath === 'function') {
|
72 | publicPath = options.publicPath(url);
|
73 | } else if (options.publicPath.endsWith('/')) {
|
74 | publicPath = options.publicPath + url;
|
75 | } else {
|
76 | publicPath = `${options.publicPath}/${url}`;
|
77 | }
|
78 |
|
79 | publicPath = JSON.stringify(publicPath);
|
80 | }
|
81 |
|
82 | if (options.emitFile === undefined || options.emitFile) {
|
83 | this.emitFile(outputPath, content);
|
84 | }
|
85 |
|
86 | return `module.exports = ${publicPath};`;
|
87 | }
|
88 |
|
89 | var raw = exports.raw = true; |
\ | No newline at end of file |