umi-plugin-mako
Version:
## Install
134 lines (132 loc) • 4.77 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/utils.ts
var utils_exports = {};
__export(utils_exports, {
getDevBanner: () => getDevBanner,
getMakoConfig: () => getMakoConfig,
getStats: () => getStats
});
module.exports = __toCommonJS(utils_exports);
var import_address = __toESM(require("@umijs/deps/compiled/address"));
var import_chalk = __toESM(require("@umijs/deps/compiled/chalk"));
var import_lodash = __toESM(require("lodash"));
var import_path = __toESM(require("path"));
function getLessSourceMapConfig(devtool) {
return devtool && {
sourceMapFileInline: true,
outputSourceFiles: true
};
}
var getMakoConfig = (config, bundleConfig) => {
var _a, _b, _c, _d;
const define = {};
function normalizeDefineValue(val) {
if (!import_lodash.default.isPlainObject(val)) {
return JSON.stringify(val);
} else {
return Object.keys(val).reduce((obj, key) => {
obj[key] = normalizeDefineValue(val[key]);
return obj;
}, {});
}
}
if (config.define) {
for (const key of Object.keys(config.define)) {
if (key.startsWith("process.env.")) {
define[key.replace(/^process\.env\./, "")] = normalizeDefineValue(
config.define[key]
);
} else {
define[key] = normalizeDefineValue(config.define[key]);
}
}
}
const generatorAlias = Object.keys(bundleConfig.resolve.alias).map((key) => {
return [key, bundleConfig.resolve.alias[key]];
});
const generatorEntry = {};
Object.keys(bundleConfig.entry).forEach((key) => {
generatorEntry[key] = bundleConfig.entry[key][0];
});
const normalizedDevtool = config.devtool === false ? false : "source-map";
return {
mode: bundleConfig.mode,
devtool: config.devtool,
autoCSSModules: true,
less: {
modifyVars: ((_a = config.lessLoader) == null ? void 0 : _a.modifyVars) || config.theme,
globalVars: (_b = config.lessLoader) == null ? void 0 : _b.globalVars,
sourceMap: getLessSourceMapConfig(normalizedDevtool),
math: (_c = config.lessLoader) == null ? void 0 : _c.math,
plugins: (_d = config.lessLoader) == null ? void 0 : _d.plugins
},
resolve: { alias: generatorAlias },
entry: generatorEntry,
// always enable stats to provide json for onBuildComplete hook
stats: {
modules: false
},
define,
sass: config == null ? void 0 : config.sass,
...(config == null ? void 0 : config.mako) || {}
};
};
var getStats = (statsJson) => {
const stats = {
compilation: {
...statsJson,
chunks: statsJson.chunks.map((chunk) => {
chunk.name = import_path.default.basename(chunk.id, import_path.default.extname(chunk.id));
return chunk;
})
},
hasErrors: () => false
};
const statsUtil = {
toJson: () => stats.compilation
};
return statsUtil;
};
var getDevBanner = (protocol, host, port) => {
const ip = import_address.default.ip();
const hostStr = host === "0.0.0.0" ? "localhost" : host;
const messages = [];
messages.push(" App listening at:");
messages.push(
` - Local: ${import_chalk.default.cyan(`${protocol}//${hostStr}:${port}`)}`
);
messages.push(` - Network: ${import_chalk.default.cyan(`${protocol}//${ip}:${port}`)}`);
return messages.join("\n");
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getDevBanner,
getMakoConfig,
getStats
});