mirror of
https://kevinblog.sytes.net/Code/Jibo-Revival-Group/JiboViteDocs.git
synced 2026-06-16 23:17:02 +00:00
Initalize
This commit is contained in:
29
node_modules/@lando/vitepress-theme-default-plus/vite/add-layout-components-plugin.js
generated
vendored
Normal file
29
node_modules/@lando/vitepress-theme-default-plus/vite/add-layout-components-plugin.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import Debug from 'debug';
|
||||
import {EOL} from 'node:os';
|
||||
|
||||
const pivot = 'export default function(app) {';
|
||||
|
||||
export default function(layouts = [], {debug = Debug('@lando/vite-plugin')}) { // eslint-disable-line
|
||||
return {
|
||||
name: 'inject-layouts',
|
||||
enforce: 'pre',
|
||||
transform: (code, id) => {
|
||||
const layoutfile = 'enhance-app-with-layouts.js';
|
||||
if (id.includes(layoutfile) && layouts.length > 0) {
|
||||
// get lines and pindex
|
||||
const lines = code.split(EOL);
|
||||
// get pivot line
|
||||
let pindex = lines.findIndex(line => line.startsWith(pivot));
|
||||
// loop through and add imports
|
||||
for (const layout of layouts.reverse()) lines.splice(pindex, 0, layout.import);
|
||||
// get pivot again
|
||||
pindex = lines.findIndex(line => line.startsWith(pivot)) + 1;
|
||||
// loop through again and add components
|
||||
for (const layout of layouts.reverse()) lines.splice(pindex, 0, layout.add);
|
||||
// debug
|
||||
debug('autogenerated layout import file %o with content %O', layoutfile, lines);
|
||||
return lines.join(EOL);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user