UNPKG

@ices/locale-webpack-plugin

Version:
48 lines 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pitch = void 0; const tslib_1 = require("tslib"); const fs_1 = tslib_1.__importDefault(require("fs")); const path_1 = tslib_1.__importDefault(require("path")); const loader_utils_1 = require("loader-utils"); const utils_1 = require("../lib/utils"); const cwd = fs_1.default.realpathSync(process.cwd()); const pitch = function () { const options = (0, loader_utils_1.getOptions)(this); const { generator, extensions, esModule } = options; const extensionsMatchRegx = new RegExp(extensions.map((ext) => ext.replace(/([.$:?=!<>\[\]()|])/g, `\\$1`)).join('|')); const query = `?${extensions.join('&')}`; if (this.resourceQuery === query || (!extensionsMatchRegx.test(this.resourceQuery) && !extensionsMatchRegx.test(path_1.default.extname(this.resourcePath).substring(1)))) { return; } this.cacheable(true); const callback = this.async() || (() => { }); const request = (0, utils_1.normalizePath)(this.resourcePath, this.context) + query; this.loadModule(request, (err) => { if (err) { callback(err); } else { try { callback(null, generator({ esModule, rootContext: cwd, resourcePath: (0, utils_1.normalizePath)(this.resourcePath, cwd), module: JSON.parse((0, loader_utils_1.stringifyRequest)(this, request)), hot: this.mode === 'development' && this.hot, })); } catch (err) { callback(err); } } }); }; exports.pitch = pitch; const localeLoader = (source) => source; localeLoader.pitch = exports.pitch; localeLoader.filepath = __filename; exports.default = localeLoader; //# sourceMappingURL=localeLoader.js.map