Skip to content

Instantly share code, notes, and snippets.

@kevboh
Last active June 29, 2021 13:41
Show Gist options
  • Save kevboh/e2e15bf06bfb904690523e48db2c35a9 to your computer and use it in GitHub Desktop.
Save kevboh/e2e15bf06bfb904690523e48db2c35a9 to your computer and use it in GitHub Desktop.
rollup config for obsidian dev w/ svelte
import svelte from "rollup-plugin-svelte";
import typescript from "@rollup/plugin-typescript";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import sveltePreprocess from "svelte-preprocess";
import copy from "rollup-plugin-copy";
import { env } from "process";
const isProd = env.BUILD === "production";
const isWatching = env.ROLLUP_WATCH === "true";
const pluginDir = env.PLUGINS_DIR;
const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP
if you want to view the source visit the plugins github repository
*/
`;
export default {
input: "src/main.ts",
output: {
dir: ".",
sourcemap: !isProd,
format: "cjs",
exports: "default",
banner,
},
external: ["obsidian"],
plugins: [
svelte({
emitCss: false,
preprocess: sveltePreprocess(),
}),
typescript({ sourceMap: !isProd, inlineSources: !isProd }),
nodeResolve({ browser: true, dedupe: ["svelte"] }),
commonjs({
include: "node_modules/**",
}),
isWatching &&
pluginDir &&
copy({
targets: [
{
src: ["main.js", "manifest.json", "styles.css"],
dest: pluginDir + "/[YOUR PLUGIN DIR]/",
},
],
hook: "writeBundle",
verbose: true,
overwrite: true,
}),
],
};
@kevboh
Copy link
Author

kevboh commented Jun 29, 2021

Some notes:

  1. Remember to update [YOUR PLUGIN DIR] to match the directory of the plugin you're working in.
  2. env.PLUGINS_DIR is an env var you'll need to set. It's the path to your .obsidian/plugins directory in whatever vault you're using for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment