feat: 调整自动引入组件,新增html展示页面。

This commit is contained in:
pixelmaxQM
2024-10-25 22:19:13 +08:00
parent 7d6270079a
commit dcd0eb20e1
4 changed files with 91 additions and 14 deletions

View File

@@ -35,10 +35,8 @@ const vueFilePathPlugin = (outputFilePath) => {
const pathNameMap = vueFiles.reduce((acc, filePath) => {
const content = fs.readFileSync(filePath, 'utf-8');
const componentName = extractComponentName(content);
if (componentName) {
let relativePath ="/" + path.relative(root, filePath).replace(/\\/g, '/');
acc[relativePath] = componentName;
}
acc[relativePath] = componentName || "UnNameComponent";
return acc;
}, {});
const outputContent = JSON.stringify(pathNameMap, null, 2);
@@ -49,7 +47,6 @@ const vueFilePathPlugin = (outputFilePath) => {
const watchDirectories = [path.join(root, 'src/view'), path.join(root, 'src/plugin')];
const watcher = chokidar.watch(watchDirectories, { persistent: true, ignoreInitial: true });
watcher.on('all', (event, path) => {
console.log(`File ${path} has been ${event}`);
generatePathNameMap();
});
};
@@ -61,8 +58,10 @@ const vueFilePathPlugin = (outputFilePath) => {
configResolved(resolvedConfig) {
root = resolvedConfig.root;
},
buildEnd() {
buildStart() {
generatePathNameMap();
},
buildEnd() {
if (process.env.NODE_ENV === 'development') {
watchDirectoryChanges();
}