vite-plugin-antd-dayjs
Version:
vite plugin for replacing moment.js with Day.js
41 lines (39 loc) • 978 B
JavaScript
/**
* fork vite-plugin-for-antd-dayjs
*/
try {
require.resolve("dayjs/dayjs.min");
} catch (e) {
throw new Error(
"vite-plugin-antd-dayjs plugin requires dayjs to be present in the devDependency " +
"tree."
);
}
const momentToDayjsPluginsInAntdVue = require("./map-to-dayjs-plugins.js");
module.exports = function vitePluginVueForAntdDayjs() {
const isAntdvueId = "moment-to-dayjs-for-antd-vue";
return {
name: "vite-plugin-antd-dayjs",
enforce: "pre",
config: () => ({
resolve: {
alias: {
moment: "dayjs",
},
},
}),
resolveId(id) {
if (isAntdvueId === id) {
console.log("resolveid id test", id);
return id;
}
},
load(id) {
if (isAntdvueId === id) {
const momentTransforeToDayjs = `import dayjs from 'dayjs';`;
const depStr = momentToDayjsPluginsInAntdVue().join("");
return momentTransforeToDayjs + depStr;
}
},
};
};