vite-plugin-antdv-fix
Version:
ant-design-vue@1.7.8不在维护,基于现在vue2 + vite + antdv已存在问题
99 lines (98 loc) • 3.31 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(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
default: () => src_default
});
module.exports = __toCommonJS(src_exports);
var import_fs = __toESM(require("fs"));
var pluginName = "vite-plugin-antdv-fix";
var fixPath = [
"calendar/index.js",
"_util/moment-util.js",
"locale-provider/index.js"
];
var cache = /* @__PURE__ */ new Map();
var antdvFix = (options = {}) => {
if (options.files)
fixPath = [...options.files, ...fixPath];
return {
name: pluginName,
configResolved(config) {
if (!config.optimizeDeps.esbuildOptions) {
config.optimizeDeps.esbuildOptions = {};
}
if (!config.optimizeDeps.esbuildOptions.plugins) {
config.optimizeDeps.esbuildOptions.plugins = [];
}
config.optimizeDeps.esbuildOptions.plugins.push({
name: pluginName,
setup(build) {
build.onLoad(
{
filter: /\.js$/
},
(args) => {
const path = args.path.replace(/\\/g, "/");
if (fixPath.some((item) => path.endsWith(item))) {
let contents = "";
if (cache.has(path)) {
contents = cache.get(path);
} else {
const source = import_fs.default.readFileSync(path, "utf-8");
contents = source.replace(`import * as moment`, "import moment");
cache.set(path, contents);
}
return {
contents
};
}
}
);
}
});
if (process.env.NODE_ENV === "production") {
if (!config.build.commonjsOptions) {
config.build.commonjsOptions = {};
}
config.build.commonjsOptions.transformMixedEsModules = true;
}
},
transform(code, id) {
if (fixPath.some((item) => id.endsWith(item))) {
code = code.replace(`import * as moment`, "import moment");
}
return {
code,
map: null
};
}
};
};
var src_default = antdvFix;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});
//# sourceMappingURL=index.js.map
;