@tarojs/webpack-runner
Version:
webpack runner for taro
86 lines • 4.69 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseHtmlScript = exports.parsePublicPath = exports.formatOpenHost = exports.addHtmlSuffix = exports.stripTrailingSlash = exports.stripBasename = exports.hasBasename = exports.addTrailingSlash = exports.addLeadingSlash = exports.getRootPath = exports.emptyTogglableObj = void 0;
const os_1 = require("os");
const path = require("path");
exports.emptyTogglableObj = {
enable: false,
config: {}
};
const getRootPath = function () {
return path.resolve(__dirname, '../../');
};
exports.getRootPath = getRootPath;
const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
exports.addLeadingSlash = addLeadingSlash;
const addTrailingSlash = (url = '') => (url.charAt(url.length - 1) === '/' ? url : url + '/');
exports.addTrailingSlash = addTrailingSlash;
const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
exports.hasBasename = hasBasename;
const stripBasename = (path = '', prefix = '') => (0, exports.hasBasename)(path, prefix) ? path.substr(prefix.length) : path;
exports.stripBasename = stripBasename;
const stripTrailingSlash = (path = '') => (path.charAt(path.length - 1) === '/' ? path.substring(0, path.length - 1) : path);
exports.stripTrailingSlash = stripTrailingSlash;
const addHtmlSuffix = (path = '') => `${path}.html`;
exports.addHtmlSuffix = addHtmlSuffix;
const formatOpenHost = host => {
var _a;
let result = host;
// 配置host为0.0.0.0时,可以转换为ip打开, 其他以配置host默认打开
if (result === '0.0.0.0') {
// 设置localhost为初值, 防止没正确获取到host时以0.0.0.0打开
result = 'localhost';
const interfaces = (0, os_1.networkInterfaces)();
for (const devName in interfaces) {
const isEnd = (_a = interfaces[devName]) === null || _a === void 0 ? void 0 : _a.some(item => {
// 取IPv4, 不为127.0.0.1的内网ip
if (['IPv4', 4, '4'].includes(item.family) && item.address !== '127.0.0.1' && !item.internal) {
result = item.address;
return true;
}
return false;
});
// 若获取到ip, 结束遍历
if (isEnd) {
break;
}
}
}
return result;
};
exports.formatOpenHost = formatOpenHost;
function parsePublicPath(publicPath = '/') {
return ['', 'auto'].includes(publicPath) ? publicPath : (0, exports.addTrailingSlash)(publicPath);
}
exports.parsePublicPath = parsePublicPath;
function parseHtmlScript(pxtransformOption = {}) {
var _a, _b, _c;
const options = (pxtransformOption === null || pxtransformOption === void 0 ? void 0 : pxtransformOption.config) || {};
const max = (_a = options === null || options === void 0 ? void 0 : options.maxRootSize) !== null && _a !== void 0 ? _a : 40;
const min = (_b = options === null || options === void 0 ? void 0 : options.minRootSize) !== null && _b !== void 0 ? _b : 20;
const baseFontSize = (options === null || options === void 0 ? void 0 : options.baseFontSize) || (min > 1 ? min : 20);
const designWidth = (input => typeof options.designWidth === 'function'
? options.designWidth(input)
: options.designWidth)(baseFontSize);
const rootValue = baseFontSize / options.deviceRatio[designWidth] * 2;
if (((_c = options === null || options === void 0 ? void 0 : options.targetUnit) !== null && _c !== void 0 ? _c : 'rem') === 'rem') {
return `!function(n){function f(){var e=n.document.documentElement,w=e.getBoundingClientRect().width,x=${rootValue}*w/${designWidth};e.style.fontSize=x>=${max}?"${max}px":x<=${min}?"${min}px":x+"px"}n.addEventListener("resize",(function(){f()})),f()}(window);`;
}
}
exports.parseHtmlScript = parseHtmlScript;
__exportStar(require("./app"), exports);
//# sourceMappingURL=index.js.map
;