mirror of
https://github.com/tuna/mirror-web.git
synced 2025-12-25 20:32:46 +00:00
Format vite config as well
Signed-off-by: Harry Chen <i@harrychen.xyz>
This commit is contained in:
parent
bb9370aee7
commit
6f9fbcfe31
137
_vite.config.mjs
137
_vite.config.mjs
|
|
@ -1,37 +1,42 @@
|
|||
import path, { resolve } from 'path'
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import ruby from 'vite-plugin-ruby'
|
||||
import components from 'unplugin-vue-components/vite'
|
||||
import legacy from '@vitejs/plugin-legacy'
|
||||
import { toSass } from 'sass-cast'
|
||||
import { Liquid, Tag as LiquidTag } from 'liquidjs'
|
||||
import path, { resolve } from "path";
|
||||
import { defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import ruby from "vite-plugin-ruby";
|
||||
import components from "unplugin-vue-components/vite";
|
||||
import legacy from "@vitejs/plugin-legacy";
|
||||
import { toSass } from "sass-cast";
|
||||
import { Liquid, Tag as LiquidTag } from "liquidjs";
|
||||
|
||||
const visualizer = await (async()=>{
|
||||
const visualizer = await (async () => {
|
||||
if (process.env.VISUALIZER) {
|
||||
return (await import('rollup-plugin-visualizer')).visualizer;
|
||||
}else{
|
||||
return (()=>null);
|
||||
return (await import("rollup-plugin-visualizer")).visualizer;
|
||||
} else {
|
||||
return () => null;
|
||||
}
|
||||
})();
|
||||
|
||||
const exposedData = ['config', 'data', 'categories'];
|
||||
const jekyllData = Object.fromEntries(exposedData.map((key) => [key, JSON.parse(process.env[`site_${key}`] || '{}')]));
|
||||
jekyllData.config.hasOwnProperty('suffix') || (jekyllData.config.suffix = null);
|
||||
const exposedData = ["config", "data", "categories"];
|
||||
const jekyllData = Object.fromEntries(
|
||||
exposedData.map((key) => [
|
||||
key,
|
||||
JSON.parse(process.env[`site_${key}`] || "{}"),
|
||||
]),
|
||||
);
|
||||
jekyllData.config.hasOwnProperty("suffix") || (jekyllData.config.suffix = null);
|
||||
|
||||
export default defineConfig(({mode})=>({
|
||||
export default defineConfig(({ mode }) => ({
|
||||
build: {
|
||||
emptyOutDir: true,
|
||||
sourcemap: mode === 'production' ? false : true,
|
||||
minify: mode === 'production',
|
||||
sourcemap: mode === "production" ? false : true,
|
||||
minify: mode === "production",
|
||||
},
|
||||
plugins: [
|
||||
(()=>{
|
||||
const importNamePrefix = 'virtual:jekyll-';
|
||||
const loadNamePrefix = '\0' + importNamePrefix;
|
||||
(() => {
|
||||
const importNamePrefix = "virtual:jekyll-";
|
||||
const loadNamePrefix = "\0" + importNamePrefix;
|
||||
|
||||
return {
|
||||
name: 'jekyll',
|
||||
name: "jekyll",
|
||||
resolveId(id) {
|
||||
if (id.startsWith(importNamePrefix)) {
|
||||
return loadNamePrefix + id.slice(importNamePrefix.length);
|
||||
|
|
@ -40,26 +45,30 @@ export default defineConfig(({mode})=>({
|
|||
load(id) {
|
||||
if (id.startsWith(loadNamePrefix)) {
|
||||
const key = id.slice(loadNamePrefix.length);
|
||||
return Object.entries(jekyllData[key]).map(([key, value]) => `export const ${key.replace("-", "_")} = ${JSON.stringify(value)};`).join('\n');
|
||||
return Object.entries(jekyllData[key])
|
||||
.map(
|
||||
([key, value]) =>
|
||||
`export const ${key.replace("-", "_")} = ${JSON.stringify(value)};`,
|
||||
)
|
||||
.join("\n");
|
||||
}
|
||||
},
|
||||
};
|
||||
})(),
|
||||
(()=>{
|
||||
(() => {
|
||||
const helpPages = jekyllData.categories.help || [];
|
||||
return {
|
||||
name: 'tuna-help-pages',
|
||||
name: "tuna-help-pages",
|
||||
resolveId(id) {
|
||||
if (id === "virtual:tuna-help-pages") {
|
||||
return '\0' + id;
|
||||
return "\0" + id;
|
||||
}
|
||||
},
|
||||
load(id) {
|
||||
if (id === '\0' + "virtual:tuna-help-pages") {
|
||||
const pages = Object.fromEntries(helpPages.map((page) => [
|
||||
page.mirrorid,
|
||||
page.url,
|
||||
]));
|
||||
if (id === "\0" + "virtual:tuna-help-pages") {
|
||||
const pages = Object.fromEntries(
|
||||
helpPages.map((page) => [page.mirrorid, page.url]),
|
||||
);
|
||||
return `export default ${JSON.stringify(pages)};`;
|
||||
}
|
||||
},
|
||||
|
|
@ -67,63 +76,71 @@ export default defineConfig(({mode})=>({
|
|||
})(),
|
||||
vue({
|
||||
template: {
|
||||
preprocessCustomRequire(id){
|
||||
if(id === "liquid"){
|
||||
preprocessCustomRequire(id) {
|
||||
if (id === "liquid") {
|
||||
return {
|
||||
render(source, options, cb){
|
||||
render(source, options, cb) {
|
||||
const engine = new Liquid({
|
||||
root: jekyllData.config.source,
|
||||
partials: path.join(jekyllData.config.source, jekyllData.config.includes_dir),
|
||||
partials: path.join(
|
||||
jekyllData.config.source,
|
||||
jekyllData.config.includes_dir,
|
||||
),
|
||||
globals: jekyllData,
|
||||
jekyllInclude: true,
|
||||
});
|
||||
engine.registerTag("fa_svg", class extends LiquidTag{
|
||||
constructor(token, remainTokens, liquid){
|
||||
super(token, remainTokens, liquid);
|
||||
this.value = token.args;
|
||||
}
|
||||
* render (ctx, emitter){
|
||||
emitter.write(`<svg class="icon"><use xlink:href="#${this.value}"></use></svg>`);
|
||||
}
|
||||
});
|
||||
try{
|
||||
const result = engine.parseAndRenderSync(source, {...options});
|
||||
engine.registerTag(
|
||||
"fa_svg",
|
||||
class extends LiquidTag {
|
||||
constructor(token, remainTokens, liquid) {
|
||||
super(token, remainTokens, liquid);
|
||||
this.value = token.args;
|
||||
}
|
||||
*render(ctx, emitter) {
|
||||
emitter.write(
|
||||
`<svg class="icon"><use xlink:href="#${this.value}"></use></svg>`,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
try {
|
||||
const result = engine.parseAndRenderSync(source, {
|
||||
...options,
|
||||
});
|
||||
cb(null, result);
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
cb(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
}),
|
||||
ruby(),
|
||||
components({
|
||||
dirs: [resolve(__dirname, '_src/components')],
|
||||
resolvers:[
|
||||
],
|
||||
dirs: [resolve(__dirname, "_src/components")],
|
||||
resolvers: [],
|
||||
}),
|
||||
legacy({
|
||||
targets: [],
|
||||
additionalLegacyPolyfills: [
|
||||
resolve(__dirname, '_src/lib/legacy-polyfill.js'),
|
||||
resolve(__dirname, "_src/lib/legacy-polyfill.js"),
|
||||
],
|
||||
}),
|
||||
visualizer({
|
||||
filename: '_stats.html',
|
||||
filename: "_stats.html",
|
||||
}),
|
||||
],
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
scss: {
|
||||
functions: {
|
||||
"jekyll-config()": function(){
|
||||
"jekyll-config()": function () {
|
||||
return toSass(jekyllData.config);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}))
|
||||
},
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
"private": true,
|
||||
"homepage": "https://github.com/tuna/mirror-web",
|
||||
"scripts": {
|
||||
"format": "prettier --write \"_src/**/*.vue\" \"_src/**/*.html\" \"_src/**/*.js\" \"_src/**/*.scss\""
|
||||
"format": "prettier --write \"_src/**/*.vue\" \"_src/**/*.html\" \"_src/**/*.js\" \"_src/**/*.scss\" *.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vitejs/plugin-legacy": "^5.3.2",
|
||||
|
|
|
|||
Loading…
Reference in New Issue