generated from tpl/obsidian-sample-plugin
			Remove custom vite plugin and just change the outDir
This commit is contained in:
		
							parent
							
								
									1caa43224e
								
							
						
					
					
						commit
						93da69910c
					
				| 
						 | 
				
			
			@ -13,6 +13,7 @@
 | 
			
		|||
	"author": "",
 | 
			
		||||
	"license": "MIT",
 | 
			
		||||
	"devDependencies": {
 | 
			
		||||
		"@guanghechen/rollup-plugin-copy": "^6.0.7",
 | 
			
		||||
		"@popperjs/core": "^2.11.8",
 | 
			
		||||
		"@sveltejs/vite-plugin-svelte": "^5.1.0",
 | 
			
		||||
		"@types/node": "^24.0.6",
 | 
			
		||||
| 
						 | 
				
			
			@ -20,6 +21,8 @@
 | 
			
		|||
		"@typescript-eslint/parser": "5.29.0",
 | 
			
		||||
		"bits-ui": "^2.8.10",
 | 
			
		||||
		"builtin-modules": "3.3.0",
 | 
			
		||||
		"dotenv": "^17.0.0",
 | 
			
		||||
		"dotenv-expand": "^12.0.2",
 | 
			
		||||
		"esbuild": "0.17.3",
 | 
			
		||||
		"esbuild-svelte": "^0.9.3",
 | 
			
		||||
		"handlebars": "^4.7.8",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,6 +8,9 @@ importers:
 | 
			
		|||
 | 
			
		||||
  .:
 | 
			
		||||
    devDependencies:
 | 
			
		||||
      '@guanghechen/rollup-plugin-copy':
 | 
			
		||||
        specifier: ^6.0.7
 | 
			
		||||
        version: 6.0.7(rollup@4.44.1)
 | 
			
		||||
      '@popperjs/core':
 | 
			
		||||
        specifier: ^2.11.8
 | 
			
		||||
        version: 2.11.8
 | 
			
		||||
| 
						 | 
				
			
			@ -29,6 +32,12 @@ importers:
 | 
			
		|||
      builtin-modules:
 | 
			
		||||
        specifier: 3.3.0
 | 
			
		||||
        version: 3.3.0
 | 
			
		||||
      dotenv:
 | 
			
		||||
        specifier: ^17.0.0
 | 
			
		||||
        version: 17.0.0
 | 
			
		||||
      dotenv-expand:
 | 
			
		||||
        specifier: ^12.0.2
 | 
			
		||||
        version: 12.0.2
 | 
			
		||||
      esbuild:
 | 
			
		||||
        specifier: 0.17.3
 | 
			
		||||
        version: 0.17.3
 | 
			
		||||
| 
						 | 
				
			
			@ -390,6 +399,26 @@ packages:
 | 
			
		|||
  '@floating-ui/utils@0.2.9':
 | 
			
		||||
    resolution: {integrity: sha512-MDWhGtE+eHw5JW7lq4qhc5yRLS11ERl1c7Z6Xd0a58DozHES6EnNNwUWbMiG4J9Cgj053Bhk8zvlhFYKVhULwg==}
 | 
			
		||||
 | 
			
		||||
  '@guanghechen/chalk.types@1.0.4':
 | 
			
		||||
    resolution: {integrity: sha512-H9cnP7BJ8wxlRk4CkGTjgn1vvuU+DvcgmCwkJUTCsbHTQ8VCXb83xF98WSElJPZfh0EL2XTqG3fD9D7Zoab7OA==}
 | 
			
		||||
 | 
			
		||||
  '@guanghechen/chalk@1.0.4':
 | 
			
		||||
    resolution: {integrity: sha512-9h6f5DOecmxX+ityDBwNVJcS91UGVp07DN4Do9Ul9X196O0Mbv44ky03ruUtf0FBRzg7Kdnf9zRtkwfSzBNeng==}
 | 
			
		||||
 | 
			
		||||
  '@guanghechen/globby@1.0.4':
 | 
			
		||||
    resolution: {integrity: sha512-ZV+1MncBbMpGtTluoRlWfQhjWf8O5J+AtFudkCw1PWSlqffn/i4kLofKWsaKWF3XFY5RAc8zIUIEjcbNRzBWSA==}
 | 
			
		||||
    engines: {node: '>= 18.0.0'}
 | 
			
		||||
 | 
			
		||||
  '@guanghechen/rollup-plugin-copy@6.0.7':
 | 
			
		||||
    resolution: {integrity: sha512-r/S3G5oNDhrV53v1BaH22rxtk9PkFmjVt7D2dNXTNFBEO+gtOu5dLf35bfp7Ar/ENPXjr2eQh/1qnmhgU70fQg==}
 | 
			
		||||
    engines: {node: '>= 18.0.0'}
 | 
			
		||||
    peerDependencies:
 | 
			
		||||
      rollup: ^2.0.0 || ^3.0.0 || ^4.0.0
 | 
			
		||||
 | 
			
		||||
  '@guanghechen/std@1.0.4':
 | 
			
		||||
    resolution: {integrity: sha512-jjFX1ud5AULLaF6koHuiIHZQMgGkwKi22D6LzkIea05zZ/I7MmR+HRzQ4+XkfcY2YvHbt9zMGyhBqJrQaiPi+w==}
 | 
			
		||||
    engines: {node: '>= 18.0.0'}
 | 
			
		||||
 | 
			
		||||
  '@humanwhocodes/config-array@0.13.0':
 | 
			
		||||
    resolution: {integrity: sha512-DZLEEqFWQFiyK6h5YIeynKx7JlvCYWL0cImfSRXZ9l4Sg2efkFGTuFf6vzXjK1cq6IYkU+Eg/JizXw+TD2vRNw==}
 | 
			
		||||
    engines: {node: '>=10.10.0'}
 | 
			
		||||
| 
						 | 
				
			
			@ -908,6 +937,18 @@ packages:
 | 
			
		|||
    resolution: {integrity: sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==}
 | 
			
		||||
    engines: {node: '>=6.0.0'}
 | 
			
		||||
 | 
			
		||||
  dotenv-expand@12.0.2:
 | 
			
		||||
    resolution: {integrity: sha512-lXpXz2ZE1cea1gL4sz2Ipj8y4PiVjytYr3Ij0SWoms1PGxIv7m2CRKuRuCRtHdVuvM/hNJPMxt5PbhboNC4dPQ==}
 | 
			
		||||
    engines: {node: '>=12'}
 | 
			
		||||
 | 
			
		||||
  dotenv@16.6.1:
 | 
			
		||||
    resolution: {integrity: sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow==}
 | 
			
		||||
    engines: {node: '>=12'}
 | 
			
		||||
 | 
			
		||||
  dotenv@17.0.0:
 | 
			
		||||
    resolution: {integrity: sha512-A0BJ5lrpJVSfnMMXjmeO0xUnoxqsBHWCoqqTnGwGYVdnctqXXUEhJOO7LxmgxJon9tEZFGpe0xPRX0h2v3AANQ==}
 | 
			
		||||
    engines: {node: '>=12'}
 | 
			
		||||
 | 
			
		||||
  dunder-proto@1.0.1:
 | 
			
		||||
    resolution: {integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==}
 | 
			
		||||
    engines: {node: '>= 0.4'}
 | 
			
		||||
| 
						 | 
				
			
			@ -1179,6 +1220,10 @@ packages:
 | 
			
		|||
    resolution: {integrity: sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==}
 | 
			
		||||
    engines: {node: '>= 4'}
 | 
			
		||||
 | 
			
		||||
  ignore@7.0.5:
 | 
			
		||||
    resolution: {integrity: sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg==}
 | 
			
		||||
    engines: {node: '>= 4'}
 | 
			
		||||
 | 
			
		||||
  immutable@5.1.3:
 | 
			
		||||
    resolution: {integrity: sha512-+chQdDfvscSF1SJqv2gn4SRO2ZyS3xL3r7IW/wWEEzrzLisnOlKiQu5ytC/BVNcS15C39WT2Hg/bjKjDMcu+zg==}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2157,6 +2202,29 @@ snapshots:
 | 
			
		|||
 | 
			
		||||
  '@floating-ui/utils@0.2.9': {}
 | 
			
		||||
 | 
			
		||||
  '@guanghechen/chalk.types@1.0.4': {}
 | 
			
		||||
 | 
			
		||||
  '@guanghechen/chalk@1.0.4':
 | 
			
		||||
    dependencies:
 | 
			
		||||
      '@guanghechen/chalk.types': 1.0.4
 | 
			
		||||
 | 
			
		||||
  '@guanghechen/globby@1.0.4':
 | 
			
		||||
    dependencies:
 | 
			
		||||
      fast-glob: 3.3.3
 | 
			
		||||
      ignore: 7.0.5
 | 
			
		||||
 | 
			
		||||
  '@guanghechen/rollup-plugin-copy@6.0.7(rollup@4.44.1)':
 | 
			
		||||
    dependencies:
 | 
			
		||||
      '@guanghechen/chalk': 1.0.4
 | 
			
		||||
      '@guanghechen/globby': 1.0.4
 | 
			
		||||
      '@guanghechen/std': 1.0.4
 | 
			
		||||
      chokidar: 4.0.3
 | 
			
		||||
      dir-glob: 3.0.1
 | 
			
		||||
      micromatch: 4.0.8
 | 
			
		||||
      rollup: 4.44.1
 | 
			
		||||
 | 
			
		||||
  '@guanghechen/std@1.0.4': {}
 | 
			
		||||
 | 
			
		||||
  '@humanwhocodes/config-array@0.13.0':
 | 
			
		||||
    dependencies:
 | 
			
		||||
      '@humanwhocodes/object-schema': 2.0.3
 | 
			
		||||
| 
						 | 
				
			
			@ -2646,6 +2714,14 @@ snapshots:
 | 
			
		|||
    dependencies:
 | 
			
		||||
      esutils: 2.0.3
 | 
			
		||||
 | 
			
		||||
  dotenv-expand@12.0.2:
 | 
			
		||||
    dependencies:
 | 
			
		||||
      dotenv: 16.6.1
 | 
			
		||||
 | 
			
		||||
  dotenv@16.6.1: {}
 | 
			
		||||
 | 
			
		||||
  dotenv@17.0.0: {}
 | 
			
		||||
 | 
			
		||||
  dunder-proto@1.0.1:
 | 
			
		||||
    dependencies:
 | 
			
		||||
      call-bind-apply-helpers: 1.0.2
 | 
			
		||||
| 
						 | 
				
			
			@ -3054,6 +3130,8 @@ snapshots:
 | 
			
		|||
 | 
			
		||||
  ignore@5.3.2: {}
 | 
			
		||||
 | 
			
		||||
  ignore@7.0.5: {}
 | 
			
		||||
 | 
			
		||||
  immutable@5.1.3: {}
 | 
			
		||||
 | 
			
		||||
  import-fresh@3.3.1:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,59 +1,50 @@
 | 
			
		|||
import { UserConfig, defineConfig } from "vite";
 | 
			
		||||
import { svelte } from "@sveltejs/vite-plugin-svelte";
 | 
			
		||||
import copy from "@guanghechen/rollup-plugin-copy";
 | 
			
		||||
import manifest from "./manifest.json";
 | 
			
		||||
import fs from "fs/promises";
 | 
			
		||||
import path from "path";
 | 
			
		||||
import builtins from "builtin-modules";
 | 
			
		||||
 | 
			
		||||
import dotenv from "dotenv";
 | 
			
		||||
import dotenvExpand from "dotenv-expand";
 | 
			
		||||
const env = dotenv.config();
 | 
			
		||||
dotenvExpand.expand(env);
 | 
			
		||||
 | 
			
		||||
export default defineConfig(async ({ mode }) => {
 | 
			
		||||
	const { resolve } = path;
 | 
			
		||||
	const prod = mode === "production";
 | 
			
		||||
 | 
			
		||||
	let outDir = "dist";
 | 
			
		||||
	if (!prod) {
 | 
			
		||||
		if (!process.env.OBSIDIAN_PLUGIN_DIR) {
 | 
			
		||||
			console.log(
 | 
			
		||||
				"Set OBSIDIAN_PLUGIN_DIR in the .env file to plugin directory to copy files to."
 | 
			
		||||
			);
 | 
			
		||||
		} else {
 | 
			
		||||
			outDir =
 | 
			
		||||
				process.env.OBSIDIAN_PLUGIN_DIR + "/" + manifest.id + "-dev";
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (outDir[0] === "~") {
 | 
			
		||||
		outDir = path.join(process.env.HOME!, outDir.slice(1));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return {
 | 
			
		||||
		plugins: [
 | 
			
		||||
			svelte(),
 | 
			
		||||
			{
 | 
			
		||||
				name: "postbuild-commands",
 | 
			
		||||
				async closeBundle() {
 | 
			
		||||
					if (prod) return;
 | 
			
		||||
 | 
			
		||||
					if (!process.env.OBSIDIAN_PLUGIN_DIR) {
 | 
			
		||||
						console.log(
 | 
			
		||||
							"Set OBSIDIAN_PLUGIN_DIR in the .env file to plugin directory to copy files to."
 | 
			
		||||
						);
 | 
			
		||||
						return;
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
					const dist =
 | 
			
		||||
						process.env.OBSIDIAN_PLUGIN_DIR +
 | 
			
		||||
						"/" +
 | 
			
		||||
						manifest.id +
 | 
			
		||||
						"-dev";
 | 
			
		||||
 | 
			
		||||
					await fs.mkdir(dist, { recursive: true });
 | 
			
		||||
 | 
			
		||||
					const copy = async (src: string, dist: string) => {
 | 
			
		||||
						await fs.copyFile(src, path.resolve(dist, src));
 | 
			
		||||
					};
 | 
			
		||||
 | 
			
		||||
					await Promise.all([
 | 
			
		||||
						await copy("./main.js", dist),
 | 
			
		||||
						await copy("./styles.css", dist),
 | 
			
		||||
						await copy("./manifest.json", dist),
 | 
			
		||||
					]);
 | 
			
		||||
 | 
			
		||||
					console.log("Copied output files to", dist);
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			copy({
 | 
			
		||||
				targets: [{ src: "manifest.json", dest: outDir }],
 | 
			
		||||
			}),
 | 
			
		||||
		],
 | 
			
		||||
		resolve: {
 | 
			
		||||
			alias: {
 | 
			
		||||
				"@components": path.resolve(__dirname, "./src/components"),
 | 
			
		||||
				"@data-sources": path.resolve(__dirname, "./src/data-sources"),
 | 
			
		||||
				"@settings": path.resolve(__dirname, "./src/settings"),
 | 
			
		||||
				"@utils": path.resolve(__dirname, "./src/utils"),
 | 
			
		||||
				"@views": path.resolve(__dirname, "./src/views"),
 | 
			
		||||
				"@src": path.resolve(__dirname, "./src"),
 | 
			
		||||
				"@components": resolve(__dirname, "./src/components"),
 | 
			
		||||
				"@data-sources": resolve(__dirname, "./src/data-sources"),
 | 
			
		||||
				"@settings": resolve(__dirname, "./src/settings"),
 | 
			
		||||
				"@utils": resolve(__dirname, "./src/utils"),
 | 
			
		||||
				"@views": resolve(__dirname, "./src/views"),
 | 
			
		||||
				"@src": resolve(__dirname, "./src"),
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		build: {
 | 
			
		||||
| 
						 | 
				
			
			@ -67,7 +58,7 @@ export default defineConfig(async ({ mode }) => {
 | 
			
		|||
			sourcemap: prod ? false : "inline",
 | 
			
		||||
			cssCodeSplit: false,
 | 
			
		||||
			emptyOutDir: false,
 | 
			
		||||
			outDir: "dist",
 | 
			
		||||
			outDir,
 | 
			
		||||
			rollupOptions: {
 | 
			
		||||
				input: {
 | 
			
		||||
					main: resolve(__dirname, "src/main.ts"),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue