UNPKG

1.79 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = loader;
7exports.raw = void 0;
8
9var _path = _interopRequireDefault(require("path"));
10
11var _loaderUtils = _interopRequireDefault(require("loader-utils"));
12
13var _schemaUtils = _interopRequireDefault(require("schema-utils"));
14
15var _options = _interopRequireDefault(require("./options.json"));
16
17function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19function 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 } // TODO revert to ES2015 Module export, when new CSS Pipeline is in place
55
56
57 return `module.exports = ${publicPath};`;
58}
59
60const raw = true;
61exports.raw = raw;
\No newline at end of file