| 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 = require("loader-utils");
|
|---|
| 12 |
|
|---|
| 13 | var _schemaUtils = require("schema-utils");
|
|---|
| 14 |
|
|---|
| 15 | var _options = _interopRequireDefault(require("./options.json"));
|
|---|
| 16 |
|
|---|
| 17 | var _utils = require("./utils");
|
|---|
| 18 |
|
|---|
| 19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|---|
| 20 |
|
|---|
| 21 | function loader(content) {
|
|---|
| 22 | const options = (0, _loaderUtils.getOptions)(this);
|
|---|
| 23 | (0, _schemaUtils.validate)(_options.default, options, {
|
|---|
| 24 | name: 'File Loader',
|
|---|
| 25 | baseDataPath: 'options'
|
|---|
| 26 | });
|
|---|
| 27 | const context = options.context || this.rootContext;
|
|---|
| 28 | const name = options.name || '[contenthash].[ext]';
|
|---|
| 29 | const url = (0, _loaderUtils.interpolateName)(this, name, {
|
|---|
| 30 | context,
|
|---|
| 31 | content,
|
|---|
| 32 | regExp: options.regExp
|
|---|
| 33 | });
|
|---|
| 34 | let outputPath = url;
|
|---|
| 35 |
|
|---|
| 36 | if (options.outputPath) {
|
|---|
| 37 | if (typeof options.outputPath === 'function') {
|
|---|
| 38 | outputPath = options.outputPath(url, this.resourcePath, context);
|
|---|
| 39 | } else {
|
|---|
| 40 | outputPath = _path.default.posix.join(options.outputPath, url);
|
|---|
| 41 | }
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | let publicPath = `__webpack_public_path__ + ${JSON.stringify(outputPath)}`;
|
|---|
| 45 |
|
|---|
| 46 | if (options.publicPath) {
|
|---|
| 47 | if (typeof options.publicPath === 'function') {
|
|---|
| 48 | publicPath = options.publicPath(url, this.resourcePath, context);
|
|---|
| 49 | } else {
|
|---|
| 50 | publicPath = `${options.publicPath.endsWith('/') ? options.publicPath : `${options.publicPath}/`}${url}`;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | publicPath = JSON.stringify(publicPath);
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | if (options.postTransformPublicPath) {
|
|---|
| 57 | publicPath = options.postTransformPublicPath(publicPath);
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | if (typeof options.emitFile === 'undefined' || options.emitFile) {
|
|---|
| 61 | const assetInfo = {};
|
|---|
| 62 |
|
|---|
| 63 | if (typeof name === 'string') {
|
|---|
| 64 | let normalizedName = name;
|
|---|
| 65 | const idx = normalizedName.indexOf('?');
|
|---|
| 66 |
|
|---|
| 67 | if (idx >= 0) {
|
|---|
| 68 | normalizedName = normalizedName.substr(0, idx);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | const isImmutable = /\[([^:\]]+:)?(hash|contenthash)(:[^\]]+)?]/gi.test(normalizedName);
|
|---|
| 72 |
|
|---|
| 73 | if (isImmutable === true) {
|
|---|
| 74 | assetInfo.immutable = true;
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | assetInfo.sourceFilename = (0, _utils.normalizePath)(_path.default.relative(this.rootContext, this.resourcePath));
|
|---|
| 79 | this.emitFile(outputPath, content, null, assetInfo);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | const esModule = typeof options.esModule !== 'undefined' ? options.esModule : true;
|
|---|
| 83 | return `${esModule ? 'export default' : 'module.exports ='} ${publicPath};`;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | const raw = true;
|
|---|
| 87 | exports.raw = raw; |
|---|