1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import loaderUtils from 'loader-utils'; 17 18const codegen = require("./codegen/index.js"); 19 20module.exports = function (source, map) { 21 this.cacheable && this.cacheable(); 22 const callback = this.async(); 23 24 const parsed = codegen.genHmlAndCss(source); 25 const loaderQuery = loaderUtils.getOptions(this) || {}; 26 if (parsed.errorType && parsed.errorType !== '') { 27 callback(parsed.errorType + ' : ' + parsed.errorMessage, ''); 28 } else { 29 switch (loaderQuery.type) { 30 case 'template': 31 callback(null, parsed.hmlCss.hml, map); 32 break; 33 case 'style': 34 callback(null, parsed.hmlCss.css, map); 35 break; 36 case 'json': 37 callback(null, parsed.hmlCss.json, map); 38 break; 39 } 40 } 41}; 42